Changing the direction of a vector
Blitz3D Forums/Blitz3D Programming/Changing the direction of a vector
| ||
How do we change the direction of a vector gradually? Given vx,vy and vz I'd like to plug in an angle change over time to curve it off into a different direction. I believe this will solve most of my problems. |
| ||
Angle around which axis? You can use a matrix rotation thing to do it. See equations 4, 5 and 6 on this page: http://mathworld.wolfram.com/RotationMatrix.html |
| ||
Yaw would be fine :) Anything involving greek symbols generally causes me to shut my eyes tightly. Am I right in assuming this is just modifying vx and vz, where vy is gravity? |
| ||
*begs* |
| ||
If you want the vector to properly rotate through an angle, you need the matrix stuff. I can post a routine that will do this, if you like. If it's okay for the vector to change direction in a "non-circular" way, then linear interpolation is easier. Also which I can post if you like. |
| ||
Post both, I'm pleased to see any code that might help. Basically I have an object which slides down a halfpipe realistically, but I'd like to change it's direction vector if I can, so as to give the player some control. Eventually it may (or may not) turn out much like skateboard/snowboard physics. |
| ||
I think I have a way to do this, and it's even (sort of) geometrically correct. I'll try to put it up after work. Or if you can find the basic vector math stuff yourself, here's the procedure: PlayerVec = The vector direction the player is moving. PlayerUpVec = The vector normal to the surface the player is on. The normal sticks out of the ground perpendicular to it. given it's a half-pipe thing, I'm assuming these two are perpendicular; this won't work if they aren't. Normalize(PlayerVec) ; makes the length of the vector 1 Normalize(PlayerUpVec) ; same tempvec = PlayerVec (cross) PlayerUpVec ; tempvec is the cross product of PlayerVec and PlayerUpVec ; this vector points to the player's left or right. Add a minus sign to swap sides. PlayerVec = LinearInterpolation(tempvec, PlayerVec, 0.1) ; Set PlayerVec to be the linear interpolation between tempvec and PlayerVec ; this "blends" between the two vectors, turning PlayerVec 10% (that's the 0.1) toward tempvec. ; to turn faster, use 0.2 or something. Normalize(PlayerVec); make length 1 PlayerVec = PlayerVec * PlayerSpeed ; PlayerSpeed is a float, telling how fast you want the player to move. So all you need is a normalize function, a cross product function, and a linear interpolate function. :D |
| ||
Couldnīt you use aligntovector here? |
| ||
This example shows aligntovector graphically. |
| ||
From Jeppe's code, it's the 0.04 here that's what you're after:AlignToVector p2,TFormedX(),TFormedY(),TFormedZ(),3,0.04 The Blitz Help on AlignToVector mentions no such thing, so I wasn't aware of it. Rob, this is definitely the thing you want. |
| ||
ahhhh thanks! align to vector based on the tformvector is a bit beyond me. I'll have a good learn from all this...! Thanks :) |