|
Title: Velocity vector and skid Post by: Dafu on January 07, 2011, 09:51:17 PM Vector math question for you fine folks,
I have a 3D velocity vector, and a 3D acceleration vector. If I simply apply acceleration to velocity I have "full skid" movement effect, the equivalent of Asteroids, where the vehicle/ship continue to move in its original direction even after it starts accelerating in a different direction. What I'm trying to figure out is the math necessary to have a controllable "skid factor" where the velocity of the vehicle/ship is dampened to align with the direction of the acceleration. So if skid factor is 1 you have Asteroids, if its 0 you have very tight control with no skid at all. So given velocity vector "v", acceleration "a", direction "d", and skidFactor "sf" d = acceleration.Normalize(); v = v + a; v = (some math to dampen the skid effect by "sf" using "d") Can anyone give me a hand? I hope I'm making myself clear. Title: Re: Velocity vector and skid Post by: andrew-101 on January 07, 2011, 10:10:30 PM You can create a dampening effect by subtracting the initial velocity / by some factor from the final velocity I suppose.
Title: Re: Velocity vector and skid Post by: Dafu on January 07, 2011, 10:45:03 PM Thanks for answering. I don't think that will work though, you're saying:
vold = v; v = v + a; v = v - (vold * sf) if sf == 1 and new velocity is close to old velocity the resulting final velocity will be close to 0. There is something missing there. Title: Re: Velocity vector and skid Post by: seanw on January 07, 2011, 11:36:02 PM I'm not completely sure what kind of object movement you're trying to simulate. However, you might want to read about Craig Reynolds' Boids and the parts about steering behaviours as this will definitely give you some ideas: http://www.red3d.com/cwr/boids/
Title: Re: Velocity vector and skid Post by: Netsu on January 08, 2011, 02:31:46 AM If you want tight controls then create a huge damping (for example multiply the velocity by 0.9 every frame) and make it so that the player have to hold the acceleration button for the ship to move.
Code: damp_factor = 0.9; // or something, experiment v = v * damp_factor; v = v + a; The only thing you have to add is a maximum velocity, otherwise the ship will accelerate endlessly. So here's a fix: Code: damp_factor = 0.9; // or something, experiment v = v * damp_factor; v = v + a; if (v.lenght > max_velocity) v.normalize(max_velocity); Title: Re: Velocity vector and skid Post by: Will Vale on January 08, 2011, 02:45:35 AM You might get on better by thinking about following a target velocity vector rather than the direction of the acceleration - you need to get a magnitude from somewhere. Then you can compute an acceleration by scaling the difference of the target and current velocities. Make sure the scaling factor doesn't cause the integrator to blow up - for very snappy control you might want to play with velocities directly rather work via accelerations.
Will Title: Re: Velocity vector and skid Post by: BorisTheBrave on January 08, 2011, 05:57:20 AM For an asteriods style game, you don't want damping, or at least very little, because ships are expected to coast forever if no keys are pressed.
You only need the max velocity check average posted. Code: v = v + a; if (v.length > max_velocity) v.normalize(max_velocity); Though it is not obvious from looking at it, like damping this will cause the ship's direction to gradually swing round to the direction of acceleration, as you describe in your post. Title: Re: Velocity vector and skid Post by: Netsu on January 08, 2011, 06:28:05 AM For an asteriods style game, you don't want damping, or at least very little, because ships are expected to coast forever if no keys are pressed. But he specifically said that he want a way to avoid that. Unless I got him wrong, and he want his ships to float but change direction instantly on player input, this would look weird though. In that case I guess you could just reset the ship velocity when the player wants to change direction. Title: Re: Velocity vector and skid Post by: bateleur on January 08, 2011, 06:39:22 AM Incidentally, for wheeled vehicles convincing tyre grip is more complex that uniform damping. In that case you only want to damp the component perpendicular to the direction of motion.
(And for an even more convincing feel you want your damping to depend on speed. Heavy damping for low speeds, lower for high speeds.) Title: Re: Velocity vector and skid Post by: BorisTheBrave on January 08, 2011, 07:15:58 AM Ok, yeah, not sure what the poster was asking for. Play around with damping & max vel to get the desired effect, anyway.
Title: Re: Velocity vector and skid Post by: Paul Jeffries on January 08, 2011, 11:45:45 AM I'm not quite sure what you're asking, but it looks like you want to damp the velocity, but only in directions that the vehicle is not facing, right? To simulate the increased friction of 'skidding' as opposed to 'rolling'?
This is actually pretty simple: - Find the vector perpendicular to the direction the vehicle is facing (i.e. take it's heading vector and rotate it by 90 degrees). Unitize it, if it isn't already. - Find the dot product (i.e. A.x*B.x + A.y*B.y + A.z*B.z) of your current velocity vector with the perpendicular unit vector. This will give you the component of the velocity in the perpendicular direction. - Multiply the perpendicular vector by this component. Multiply this by a drag factor (or some more accurate representation of drag). - Subtract the resultant vector away from your velocity. Hope this helps! Title: Re: Velocity vector and skid Post by: Dafu on January 08, 2011, 01:06:17 PM Thank you all for your excellent responses! Paul your solution looks like exactly what I need. I will give it try.
I should have clarified in the original post that this is for simple cartoon-ish car physics. Title: Re: Velocity vector and skid Post by: Netsu on January 08, 2011, 03:40:26 PM I should have clarified in the original post that this is for simple cartoon-ish car physics. Now this makes a big difference :) In this case Paul's advice is definitely best. |