A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Neo » Sun Nov 04, 2012 11:28 am
Knowing that current player controller is unable to jump, I write my own function to let it jump by adding impulse to the newton body.
But now I get stuck on one problem: how can I get to know whether my player is on the floor?
I read the player controller's source code and marc's controller's code, however, that makes me more confused...I cannot understand his code...
How does this stuff work? Or, how can I get the player's state (if it is on the floor) directly from the entity of the player controller?
-
Neo
-
- Posts: 127
- Joined: Fri May 11, 2012 12:29 pm
- Location: China,Sichuan
by Julio Jerez » Sun Nov 04, 2012 2:17 pm
are you using these CustomPlayerControllerManager controller?
if you are the controller should jump,
the function that set the player velocity take these arguments
- Code: Select all
dVector CalculateDesiredVelocity (dFloat forwadSpeed, dFloat lateralSpeed, dFloat verticalSpeed, const dVector& gravity, dFloat timestep) const;
the third paramenet VerticalSpeed, is the impulsive velocity of a jump. It si just than in teh demo I pass 0.0, try passing a possitive valeu and it spodul jump, and behave correctly while in the air.
Ok I added a function:
const dVector& GetGroundPlane() const
when the player in on solid ground, it will return and plane equation, of teh form
a * x + a * y + a * x + w = 0
x, y, z is a unit vector
you can use like this
- Code: Select all
dVector floor = player->GetGroungVector();
if ((floor % floor) > 0.0f) {
// player is on floor, do what you wnat here.
}
Sync to SVN to get it.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Sun Nov 04, 2012 2:34 pm
If you have problems, later I will add a Jump demo, to the sandBox demo.
but you have to tell me if this is the player that you are using, or if you has tested teh one in the sandbox demo.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Neo » Mon Nov 05, 2012 12:06 am
I use the CustomPlayerController interface to create controller.
And where are these funtions?
Last edited by
Neo on Mon Nov 05, 2012 4:23 am, edited 2 times in total.
-
Neo
-
- Posts: 127
- Joined: Fri May 11, 2012 12:29 pm
- Location: China,Sichuan
by Neo » Mon Nov 05, 2012 12:25 am
OK, I see the demo has added the player controller, learning it...
BTW, sandbox crushed when start rendering again, so I have to recomplie it...
-
Neo
-
- Posts: 127
- Joined: Fri May 11, 2012 12:29 pm
- Location: China,Sichuan
by Julio Jerez » Mon Nov 05, 2012 9:51 am
each time you synk you should recompile the code.
I make the inteface much simpler,
you just call
void SetPlayerVelocity (dFloat forwadSpeed, dFloat lateralSpeed, dFloat verticalSpeed, dFloat headinAngle, const dVector& gravity, dFloat timestep);
when verticalSpeed is larger than zero the player will jump.
The demo placer places 26 player in a mesh all collidable and you can walk an djump around the complete mesh
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Neo » Tue Nov 06, 2012 2:55 am
I see...However, there is a bug in your demo, Julio:
The player would jump in the air again and again into the sky if I press and release the button 'J' constantly.
In my view, the jump condition should be like this:
- Code: Select all
if((the jump button is pressed)&&(player is on the floor)){
//jump code;
}
That's the reason I need to know whether player is on the ground.
-
Neo
-
- Posts: 127
- Joined: Fri May 11, 2012 12:29 pm
- Location: China,Sichuan
by Julio Jerez » Tue Nov 06, 2012 8:51 am
To find out if a player is airborne, you call const dVector& GetGroundPlane() const if the vector is zero, it means it is on the air
- Code: Select all
const dVector& ground = player->GetGroundPlane();
if (ground % ground) < 1.0e-3f) {
[layer is on air
}
you need to check that on your application I can not make part of the player update code, some application, ex children games, do jump allow for players do double jumps.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 0 guests