A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by OldSkhool » Fri Jul 11, 2008 7:05 pm
I'm trying to make a character that is physics effect. When the character does not collide with the ground he gets downward gravity applied to him. When he is touching he gets 0 downward gravity. I do this so he won't slide down a ramp when standing there. This works fine in my code. Problem is when the character is on the ground and I apply 0 gravity he registers off the ground. Then he is on the ground again so It creates a jumpy effect that is messing with what I want to do. I am telling if he is on or off with callbacks. If I apply no vertical force why is he leaving the ground? Any suggestions?
-
OldSkhool
-
- Posts: 3
- Joined: Tue Jun 24, 2008 6:31 pm
by Gianluca » Sat Jul 12, 2008 5:57 am
Instead of setting gravity to zero... try to setMass to zero... so, the body will become statically and Newton block it.
Then you can reactivate the physic at the successive step... or move it manually.
-
Gianluca
-
- Posts: 53
- Joined: Fri Nov 11, 2005 4:37 am
- Location: Rome - Italy
-
by OldSkhool » Sat Jul 12, 2008 12:17 pm
I gave that a try but when I returned the mass to 1.0 it remained frozen in place even when I was applying force.
-
OldSkhool
-
- Posts: 3
- Joined: Tue Jun 24, 2008 6:31 pm
by JernejL » Sat Jul 12, 2008 6:55 pm
is the body autofreeze on? tried unfreezing it?
-
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by raider » Sun Jul 13, 2008 8:44 am
This goes into a rather advanced area if you want to counterract slope forces. FPS physics models have to address it, but if you want a simpler idea, follow this pseudocode:
While touching the ground:
Get the velocity of the object.
Apply a force with inverse values to the velocity.
This brings the object to a stop while it is touching the ground. Be advised that if you change the mass of the object, the strength of the force needs to increase too; just multiply each part (x, y, z) of the velocity by the object mass, then apply it with inverse values (-x, -y, -z).
~Raider
Edit: And, by the way. He is probably leaving the ground because when you set the mass to 0, the collision solving momentarily pushes him upwards, and since the mass is zero, he floats away..
Keith: We tuna and egg.
Keith: ...
Keith: *verb
-
raider
-
- Posts: 1
- Joined: Fri Jul 04, 2008 7:04 am
by OldSkhool » Thu Jul 17, 2008 10:42 pm
thanks for replying.
Here's my code in the main loop:
- Code: Select all
// CONTROLS
if(keys[irr::KEY_KEY_W])
{
playerControl->velocity.Z = 10.0f;
playerControl->zStop = false;
}
else if(keys[irr::KEY_KEY_S])
{
playerControl->velocity.Z = -10.0f;
playerControl->zStop = false;
}
else
{
if( playerControl->onGround )
{
playerControl->zStop = true;
}
else
{
playerControl->zStop = false;
playerControl->velocity.Z = 0.0f;
}
}
if(keys[irr::KEY_KEY_D])
{
playerControl->velocity.X = 10.0f;
playerControl->xStop = false;
}
else if(keys[irr::KEY_KEY_A])
{
playerControl->velocity.X = -10.0f;
playerControl->xStop = false;
}
else
{
if( playerControl->onGround )
{
playerControl->xStop = true;
}
else
{
playerControl->xStop = false;
playerControl->velocity.X = 0.0f;
}
}
if( playerControl->onGround )
{
playerControl->yStop = true;
}
else
{
playerControl->velocity.Y = playerControl->gravity;
playerControl->yStop = false;
}
Here's my force and velocity callback:
- Code: Select all
control* playerControl = (control*)NewtonBodyGetUserData( newton );
irr::core::matrix4 m;
m.setRotationDegrees( playerControl->mesh->getRotation() );
dVector torque;
NewtonBodyGetVelocity(newton, &torque.m_x);
if( playerControl->xStop )
{
playerControl->velocity.X = -1 * torque.m_x;
}
if( playerControl->yStop )
{
playerControl->velocity.Y = -1 * torque.m_y;
}
if( playerControl->zStop )
{
playerControl->velocity.Z = -1 * torque.m_z;
}
m.transformVect( playerControl->velocity );
dVector force(playerControl->velocity.X,
(playerControl->velocity.Y),
playerControl->velocity.Z);
NewtonBodySetForce(newton, &force.m_x);
This seems like it would work but my character still floats around when I'm not pressing anything. He also constantly collides and uncollides with the ground. I never mess with the object's mass I am getting so frustrated with this SDK, is there a engine that actually does what I tell it to do out there?
-
OldSkhool
-
- Posts: 3
- Joined: Tue Jun 24, 2008 6:31 pm
by JernejL » Fri Aug 01, 2008 2:42 pm
I guess we have a spamming problem again, was the signup captcha text algorythm reset to basic one again when Alain upgraded the forum?
-
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Julio Jerez » Fri Aug 01, 2008 2:50 pm
I think so, can you fix it please.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JernejL » Fri Aug 01, 2008 4:56 pm
hmm, i checked the signup form and the captcha algorythm used is very hard to read using ocr, i would say this spammer must have signed up manually, you should just delete his posts and ban him from using the forum.
-
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest