Acceleration woes
by Derek Kittrell · in Torque Game Builder · 03/04/2005 (7:25 pm) · 4 replies
Okay, I'm having some issues with my acceleration code. I'm currently working on a top-down shooter--I guess the controls are somewhat similar to asteroids.
I get the x and y vector and multiply that by an acceleration modifier. Now, I can limit whether or not to add the acceration value if the current x or y value is less than my defined max velocity, but that of course will not work if I'm moving at an angle other than 0, 90, 180, and 270. It occured to me to use vectorlength2d for the player's current velocity to compare to my maxspeed value, but that doesn't seem to work how I want either. Does anyone have any pointers on how to best achieve this sort of thing? I hate to be a bother, but this one really has me stumped.
I get the x and y vector and multiply that by an acceleration modifier. Now, I can limit whether or not to add the acceration value if the current x or y value is less than my defined max velocity, but that of course will not work if I'm moving at an angle other than 0, 90, 180, and 270. It occured to me to use vectorlength2d for the player's current velocity to compare to my maxspeed value, but that doesn't seem to work how I want either. Does anyone have any pointers on how to best achieve this sort of thing? I hate to be a bother, but this one really has me stumped.
About the author
#2
03/05/2005 (4:07 am)
Thanks for your example, Philip. My problem was a little different. The player's ship is set to accelerate at a fixed modifier until it reaches max speed. I was correct in thinking that vectorlength2d would work for what I needed, but I was a little off in the execution. Now it seems to work, but it seems like it takes a really long time to alter your course.. it may just need number tweaking, or I may have screwed something up yet again.. Not sure. I can post what I have if it would be useful to anyone, or if anyone wouldn't mind taking a look to see how to improve upon it. Just let me know.
#3
03/05/2005 (10:35 am)
Glad you got the acceleration working Derek. Feel free to post your code if you want someone to help figure out the turning thing.
#4
MaxSpeed is 20, AccelMod is 1.25, and RotationSpeed is 300. It feels kinda like sliding on ice, as it takes a really long time to alter your vector, especially in small changes in your rotation.
I don't really know enough about physics values to know which sorts of things I would need to tweak to get this feeling right, so any help at all would be greatly appreciated.
03/06/2005 (11:38 pm)
Okay, this is my movement code. I'm sure it's not perfect, and it may even be bad in places. Basically, I am wondering if anyone would mind taking a look to see if it could be improved in any way. It just feels a little strange in the game. I am beginning to suspect that this is more a physics thing than a code thing, but that's why I was hoping for some pointers, because I'm not sure.MaxSpeed is 20, AccelMod is 1.25, and RotationSpeed is 300. It feels kinda like sliding on ice, as it takes a really long time to alter your vector, especially in small changes in your rotation.
I don't really know enough about physics values to know which sorts of things I would need to tweak to get this feeling right, so any help at all would be greatly appreciated.
Torque Owner Philip Mansfield
Default Studio Name
function redplayerCW() { $redPlane.setAngularVelocity( -$redTurnRate ); $redturn=true; redplayerTurnSched(); } //red player turns anti-clockwise function redplayerCCW() { $redPlane.setAngularVelocity( $redTurnRate ); $redturn=true; redplayerTurnSched(); } //red player turn scheduler function redplayerTurnSChed() { if($redturn) { $redPlane.setLinearVelocityPolar(($redPlane.getRotation()-90),$redSpeed); //Every 1/10 second apply thrust schedule(100, 0, "redplayerTurnSched"); } } //red player stops turning function redplayerTurnStop() { if ( $redPlane.getAngularVelocity() != 0 ) { $redPlane.setAngularVelocity( 0 ); $redturn=false; } }$redTurnRate is set to 90 in my case, so that's a 90 degree rotation in 1 sec.
I use getRotation()-90 as I want my player move left at the start of the game.
That does all the stuff I need and causes my planes to be able to fly in loops. If you wanted the player to drift in a direction and only change direction when they reapply thrust, then move:
from the redTurnSched function and put it into your 'apply thrust' function. That should give you the desired effect.