SetForwardMovementOnly
by Steve Way · in Torque Game Builder · 09/01/2006 (10:00 pm) · 8 replies
I'm new to TGB. So far I really like it and I'm impressed. I've decided to prototype some game ideas.
I'm having problems working out an issue (described below) with library methods, so I'm wondering if I need to special code some new methods to achieve the result I desire.
I'm trying to make a simple prototype to drive a sprite car around a racetrack. I'm using "up" for acceleration, "down" for break, and "left" and "right" to turn the car and control the direction. The car is oriented East-West along the x-axis as far as the sprite is concerned, but the default forward direction for the sprite sends the car up the screen in the y-axis. I can then turn the car down the track, but the car looks like it is driving sideways.
Is there any default method I can use to set the starting orientation of a sprite for a level so that I could orient the forward direction to be moving left across the screen (in line with the sprite)?
I'm having problems working out an issue (described below) with library methods, so I'm wondering if I need to special code some new methods to achieve the result I desire.
I'm trying to make a simple prototype to drive a sprite car around a racetrack. I'm using "up" for acceleration, "down" for break, and "left" and "right" to turn the car and control the direction. The car is oriented East-West along the x-axis as far as the sprite is concerned, but the default forward direction for the sprite sends the car up the screen in the y-axis. I can then turn the car down the track, but the car looks like it is driving sideways.
Is there any default method I can use to set the starting orientation of a sprite for a level so that I could orient the forward direction to be moving left across the screen (in line with the sprite)?
#2
09/02/2006 (7:44 am)
Haha, thanks Philip! I was hoping I wouldn't have to do that. It also means that all of my levels will have to start racing towards the top of the screen as opposed to the side.
#3
but i wouldn't use the foward thing all the time, if at all. There's a tutorial in TDN (once you buy the engine) that shows how to make vechicles work. That had forward as the direction the vechicle is facing.
09/02/2006 (9:08 am)
They don't HAVE to start racing toawrds the top. Rotate your car right on level start. Then you can go sideways. but i wouldn't use the foward thing all the time, if at all. There's a tutorial in TDN (once you buy the engine) that shows how to make vechicles work. That had forward as the direction the vechicle is facing.
#4
The other option is not to use setForwardMovementOnly and instead use rotation and setLinearVelocityPolar. By applying an offset (either + or - 90 degrees depending if your car is facing left or right) things should work out OK. I'm doing something simialr with some sidescrolling planes. The planes are drawn facing towards the left of the screen but by changing the rotation, modifying it and feeding into setLinearVelocityPolar then everything works out nicely.
09/02/2006 (9:15 am)
Not necessarily, because if your car is pointing up with setForwardMovementOnly, then rotating it 90 degrees will cause it to drive towards the right of the screen. Rotating it 270 will make it go towards the left. You will just need to orient your car at the start of the level.The other option is not to use setForwardMovementOnly and instead use rotation and setLinearVelocityPolar. By applying an offset (either + or - 90 degrees depending if your car is facing left or right) things should work out OK. I'm doing something simialr with some sidescrolling planes. The planes are drawn facing towards the left of the screen but by changing the rotation, modifying it and feeding into setLinearVelocityPolar then everything works out nicely.
#5
09/02/2006 (9:16 am)
Heh, Stephen got in there whilst I was typing (and being distracted by the football).
#6
09/02/2006 (10:33 am)
Thanks a lot guys. I will use those methods. Didn't see the vehicle tutorial in TDN but I will look for it.
#7
Implementing a brake would be as easy as adding a new key binding, and perhaps copying the math for decelleration and tweaking it to have a greater effect.
09/02/2006 (10:26 pm)
@Steve, zoulcreations.com/tgb/ZCdemoCar.zip -- that's a demo I made a week or so ago ... it's a car that drives around a track, using acceleration and decelleration ... does not implement a 'brake', but does implement a vehicle that can turn ... I believe it uses setLinearVelocityPolar and obtains the car sprites current roation as the angle and then applies some math to determine it's speed ... Implementing a brake would be as easy as adding a new key binding, and perhaps copying the math for decelleration and tweaking it to have a greater effect.
#8
09/03/2006 (9:58 am)
Awesome! Thank you David. I'll check it out immediately!
Torque Owner Philip Mansfield
Default Studio Name
It would be useful if there was a way to specify 'forward' as a particular angle, but it would probably play havoc with the physics system.