A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by sybixsus » Thu Oct 29, 2009 9:07 pm
I'm using Newton for my game, and I want to be able to throw an object from one actor to another. It's a physics-controlled body, so I need to do it the Newton way, and I'm not sure what would be.
Essentially, I have the point (in World space) where the object leaves the hand of the thrower and an approximate position (in World space) of where the recipients hand will be. The Y (height) coordinate will not necessarily be the same between the two positions. Of course, I know the mass of the object, and the gravity of the world. If necessary, I can supply a given time that it should take for the projectile to reach its target.
Can someone tell me (in fairly simple terms) how to calculate a vector to pass to AddImpulse which will cause my object to fly from Point A to Point B (without bouncing)?
-
sybixsus
-
- Posts: 6
- Joined: Fri Jan 12, 2007 7:27 pm
by Julio Jerez » Fri Oct 30, 2009 7:59 am
it is a single body?
if it is a single body you can set a path from A to B and then in each frame plot a position base of teh time step.
teh you can use the CreateCustomKinematicController (const NewtonBody* targetBody, dFloat* attachmentPointInGlobalSpace), for teh Joint library
you constrating teh position only, and set teh joint target to the point in teh path
something like
you can hook a function callbacl to the Joint twh will evaluate teh Path for A to B an dwhen it reach B will auto destroy
- Code: Select all
static void EvaluatePath (const NewtonUserJoint* me, dFloat timestep, int threadIndex)
{
//Calculate the Next Position and orination in teh Path in Matrhx
CustomKinematicControllerSetTargetMatrix (me, &matrix[0][0]);
//if Postion reache B destroy Joint
}
Joint = CreateCustomKinematicController (targetBody, pivot in body)
CustomSetUserData(g_pathFollow, path);
CustomSetDestructorCallback(g_pathFollow, FollowPath::Destroy);
CustomSetSubmitContraintCallback (g_pathFollow, FollowPath::EvaluatePath);
See the path follow demo JointTutorial in the wiki toturial for 2.00
there is a Path follow demo when and object is follwing a circular path, I guess is similar to what you need.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by sybixsus » Fri Oct 30, 2009 3:30 pm
Thanks for the suggestion, but I'm not able to do that. I'm restricted to the features that I can use, and in this instance, I have to find a solution which can be used with AddImpulse. It is a single body. I just need to calculate the correct impulse vector to add in order to move the body from PointA to PointB.
-
sybixsus
-
- Posts: 6
- Joined: Fri Jan 12, 2007 7:27 pm
by Julio Jerez » Fri Oct 30, 2009 4:17 pm
Well Impulse is Mass time Change Velocity
If you apply the impulse at the body origin, you can detrimu teh direction lik ethis
dir = Pb - Pa
dist = Mag (dir)
dir = Normalize(Dir)
veloc = dir.Scale (dist/time)
veloc -= dir.Scale (Dot (BodyGetVeloc() , dir)
Impulse = veloc.Scale (mass)
the you sset tha velocity to the Body.
It will only give you and aproximation because it does no cosider anythong tha coudl havve in between.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by sybixsus » Fri Oct 30, 2009 6:05 pm
Thanks for that. That makes a good deal of sense, but it doesn't account for gravity, does it? So when I apply the impulse, it drops into the ground almost immediately. Incidentally, the object will have a zero velocity at the moment the impulse is applied, if that's important.
I'm fine with it not accounting for anything that's in the way. That's the behaviour I want.
-
sybixsus
-
- Posts: 6
- Joined: Fri Jan 12, 2007 7:27 pm
by Julio Jerez » Fri Oct 30, 2009 7:00 pm
For Gravity all you need to do is add the vertical velocity to make sure the body is in the air during the fligh,
Once you get the linear velocity from A to B, the question is. How much vertical velocity do I need to apply to body in order to keep in the air from amound of time T?
With that information all you need to do is to use the freefall formulae to calculate what velocity. given the desired amound of time in the air.
hb = ha + v * t + 0.5 * g * t * t
0.5 * t * t * g + v * t + hb – ha = 0
G is gravity
V is the initial body vertical velocity of the body,
hb is the vertical position in point B
ha is the vertical position in point A
Solving for V you get
V = (hb – ha) / t – 0.5 * G * t
And this is the vertical velocity you add to the impulsive velocity you calculated before.
Now the shell will follow a parabolic trajectory intead of a stright one.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by sybixsus » Sat Oct 31, 2009 10:52 pm
Aha, yep, that seems to be just about perfect. Thank you very much for the help, Julio.
-
sybixsus
-
- Posts: 6
- Joined: Fri Jan 12, 2007 7:27 pm
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 2 guests