|
Post by delvarworld on Mar 9, 2006 5:59:50 GMT 1
I have an object at x#, y#, z# and I want to give it a force towards x2# y2# z2# with a force multiplier of power#
For some reason I can't get this to work. Can someone whack up some psuedocode so I can get an idea how to do this? All of the examples seem to use ray casting as their math, but I already know the object position and direction so I dont' need to cast a ray, and I can't figure out how to move it in a certain direction (I know I'm dumb)
|
|
|
Post by delvarworld on Mar 11, 2006 4:16:14 GMT 1
Hello!
|
|
|
Post by walaber on Mar 11, 2006 22:38:58 GMT 1
NDB_SetVector 1, x2#-x1#, y2#-y1#, z2#-z1# NDB_NormalizeVector 1 NDB_SetVector 1, NDB_GetVector_X(1) * power#, NDB_GetVector_Y(1) * power#, NDB_GetVector_Z(1) * power#
now add this vector as a force on the body.
p.s. I haven't used DBpro or the wrapper in a LONG time, so some of the commands might be wrong, but basically you take (goalPos - currentPos), then normalize that, and scale by power.
|
|
|
Post by kjelle69 on Mar 12, 2006 1:01:26 GMT 1
And I am sorry that I am so busy with my job right now so that I cant give the users the proper support they deserve... But I'll try to hang around as much as possible. Also want to finish off the 1.5x wrapper.
|
|
|
Post by delvarworld on Mar 13, 2006 3:29:58 GMT 1
Ok, then I'm totally stumped. Here's my code, in order: First, move the camera forward and put the grenade there, and use that position as the start for the vector: move camera 2.0
x1# = camera position x() : y1# = camera position y() : z1# = camera position z()
position grenade, camera position x(), camera position y(), camera position z() Then move the camera forward again, because this is the direction we want to throw the grenade (away from the camera). Get the new position for the vector. move camera 2.0
x2# = camera position x() : y2# = camera position y() : z2# = camera position z()
Then move the camera back... move camera -4.0 Then use Walaber's code to set the vector: NDB_SetVector 1, x2#-x1#, y2#-y1#, z2#-z1# NDB_NormalizeVector 1 NDB_SetVector 1, NDB_GetVector_X(1) * grenadeThrowPower#, NDB_GetVector_Y(1) * grenadeThrowPower#, NDB_GetVector_Z(1) * grenadeThrowPower#
NDB_BodyAddForceGlobal grenade NDB_NewtonWorldUnfreezeBody grenade That's my code broken up with comments. Now, what usually happens is that the grenade doesn't seem to get any force at all and it just flops down right in front of the player. Sometimes it does get a force, but the weirdest thing happens. The grenade throws properly, but the player SHOOTS off about half a mile in the opposite direction. I throw a grenade at full power and suddenly my player is outside the map from a huge force. I've checked for the following things: Yes, I make sure grenadeThrowPower# is a reasonable value No, the player and grenade object numbers are never the same I have no idea why this happens and I'm sad now
|
|