Game Development Community

SetLinearVelocityY

by Jeramy79 · in Torque Game Builder · 05/14/2008 (2:32 pm) · 14 replies

I've got a question about the setLinearVelocityY function.

Why does a negative number move an object UP along the Y Axis instead of DOWN?

Example from Fish Game Tutorial:

function fishPlayerUp()
{
$FishPlayer.setLinearVelocityY( -15 );
}


This moves the fish upward. Now I'm not the brightest mathmatician, but I do know that in a graph positive numbers on a Y axis are usually above the Origin not below it.

|
| <- positive Y
|
-----+-------
|
| <- Negative Y
|


setLinearVeloctiyX works just like it should with Negative numbers going Left along the X Axis and Positive numbers going Right along the X Axis.

Anyone know why this was done this way?

#1
05/14/2008 (2:41 pm)
In game engines there is no consensus as to which way is positive and negative. So... Thats just how it is in TGB.

If you are in the editor and look in the editor, drag an object around in your scene and look at how its position changes. Up is more negative, down is more positive. Therefore, a positive velocity makes your position more positive and hence downward.
#2
05/14/2008 (2:49 pm)
Jeramy,

It's was done like this to more closely represent a typical coordinate system used when referring to the screen e.g. screen-space. In lots of cases the origin is at the top-left with positive X values moving right and positive Y values moving down. This is the case with TGB.

If it had been set with the origin in the bottom-left with positive X values moving right and positive Y values moving up (typically seen on graphs) then I'm sure there'd be someone asking here why it wasn't done the other way around. ;)

To be fair though, it was a personal preference at the time when I originally developed the code and nobody questioned it early on so it stuck. It's quite common though to have to adjust to different coordinate systems when working with engines/graphics api's.

It's a skill you're forced to learn. My wife says I don't know my up from down sometimes so it does sound like you to would agree!

Melv.
#3
05/14/2008 (3:02 pm)
That definitely answers my question. I was imagining the Origin to be in the dead center of the Scene. I didn't even think about the origin being somewhere else.
#4
05/14/2008 (3:08 pm)
Jeramy,

In TGB the rules above apply but you are free to change the origin to whatever you wish. Indeed you can set the camera view to be whatever size you like at whatever position you like. The only constraint being that the positive X points right and the positive Y points down.

I placed the origin in the center of the screen because the original demos were all showing quite cool rotation and all objects defaulted to position (0,0). This meant that objects appeared at the top-left centered at (0,0) so you could only see the lower-right quandrant of them.

This sucked so I simply set the default to have the origin in the center of the screen. This way, creating an object with defaults meant it was always smack in the center of the screen. Again, it's one of those things that just stuck.

It's obviously real easy to move the camera or change its defaults.

Hope this helps,

Melv.
#5
05/14/2008 (9:33 pm)
Pretty neat info... i always wondered why was that, but never bothered to ask about it, since i got used to it pretty quick.
#6
05/15/2008 (12:15 am)
Ask away and I will tell. Forum titles with "Melv" in them always get my attention. ;)

Melv.
#7
05/15/2008 (12:20 am)
Melv, got a bug for you real quick.

I'm doing the Fish Game tutorial and have just gotten to the part where you set the World Limit to Clamp. I've done all the steps up to that point and they all work perfectly. Well I set my fishes World Limit to Clamp, and when I start it up the fish is gone. The only way i can even find it is by going into the Object Tree, selecting it, and resetting it's position to X: 0 Y: 0. It is somehow getting set to 5007.500 on x and y when it's started up. Even just shutting down TGB and reloading the project does the same thing. Even after I set it to 0 and start it back up it still goes back to 5007.500. However, if I take the World Limit and set it to OFF, it stays at 0,0 like it is supposed to.

It's also doing this for Sticky, Kill and bounce. NULL seems to work like OFF though.

I even started a completely new project with nothing in it except a plain old fish, and it does the same thing.
#8
05/15/2008 (2:15 am)
Could you send your script to "melv (d o t) may ( a t ) gmail (d o t) com" so that I can look at it?

Melv.
#9
05/15/2008 (11:13 am)
I'll send it over once I get off from work. It's exactly like the Fish Game Demo tutorial though. I even tried to cut and paste it and it still happens.
#10
05/15/2008 (4:14 pm)
Email Sent
#11
05/16/2008 (1:41 am)
Okay so I figured out the problem. I didn't set the Min Bounds or Max Bounds. Someone should add that into the tutorial because it says nothing about that. I really don't even know what I should set them to.
#12
05/20/2008 (11:46 am)
Well... maybe in those tuts its not explained, but in the shooter demo that used to come with TGB (havent tried the last one), they said especifcally to set the wrold limits in the editor (or by code if you want), cuz the world limits for every object in TGB its PRETTY DARN HIGH, and unless you want that object stayin in the scene forever, you should set the world limits a lil bigger than the camera view... at least thats what i do everytime (on the editor or with scripts while creating new objects).
#13
05/20/2008 (12:02 pm)
Be careful setting world-limits though as there's a performance overhead of an object having them set. Only do it if you absolutely need to.

Just a heads-up.

Melv.
#14
05/20/2008 (7:29 pm)
I know this was already answered, but I thought I'd add my two cents. :-)

Coordinate systems when it comes to displaying things on the screen are always from the top left. With positive X going right and positive X going down. It's done this way in all image editing software, and to the best of my memory, all programming languages I've dealt with (starting with BASIC).

It didn't make sense to me either because of the way the coordinate system works in math, especially pertaining to graphs, but that's just the way it works with display.

You should expect it to work this way, and only be surprised if it doesn't (as Melv already mentioned).