Game Development Community

Traveling by vector

by Matthew Kaplan · in Torque Game Builder · 06/24/2006 (12:40 pm) · 4 replies

Hello everyone,

I'm new to torque as of this week and the tutorials have been going well for me. I bought torque for a few reasons, one of the big ones being that it supports sprite rotation. In another older engine, I made a fun asteroid game and I want to do the same with torque. What I'm trying to do is have a single image for a ship, and the ability to rotate that image in any direction and then travel forward in that direction. So far, all the movement I've seen is based on axes, not vectors. I want the player to control the orientation of the ship, and then be able to travel in that orientation. Is there a way to do movement by angle instead of by axes?

Thanks for any help

About the author

Recent Threads


#1
06/24/2006 (12:45 pm)
Yes there is. All physical movemet commands have a angle version that takes an angle and a value. SetPosition should not be used anyway unless you know upfront that you don't need any collision.
#2
06/24/2006 (4:51 pm)
I think I found the right command, but I'm having a lot of trouble using it.

*********************

if(%this.moveLeft)
{
$ShipPlayer.setLinearVelocityPolar(shipDirection++, shipSpeed)
}

*********************

So this is a little snippet of code I was trying out. shipDirection and shipSpeed are both dynamic fields, and this code is being used by a player controlled ship. I'm getting an error when it compiles though. I know hardly anything about using torque so I'm wondering if I can actually change dynamic fields with the ++ command. I know they don't need to be dynamic fields because I'm changing the field in game, not in the editor, but I really don't know where else to define speed and direction. Could someone help me out by posting a little bit of sample code or explaining to me what I'm doing wrong (a lot I'm sure.)

Thanks
#3
06/25/2006 (4:20 pm)
Ah, that doesn't look like it would work to me, I'd recommend to use a variable (not sure if there is one already built in..)

something like:
**********************
$ShipPlayer.currentangle++;
$ShipPlayer.setLinearVelocityPolar($ShipPlayer.currentangle, shipSpeed);
**********************

I'm not clear on how the engine works all the time, but the 'Z++' just works like 'Z=Z+1', but easier. It doesn't make sense to try using that as an argument (parameter?).


Oh, and you forgot the semicolon. :)

If someone knows more, tell the man!

------

You know you're a programmer when you use semicolons instead of periods;
#4
06/26/2006 (5:31 am)
To get the current rotation of an object you want:

%thing.getRotation();

Even though %thing.rotation is exposed, you should generally avoid directly modifying the values of fields on an object. It's much safer to use accessor methods such as getRotation/setRotation.

Edit: spelling