Sign in to follow this  

Character Controller Problems

This topic is 3660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright, I am building a character controller in Newton Game Dynamics. It consists of a elliptical shape for the body of your player and a constraint to keep it upright. I have two main problems with it. The first is that, when the character body weighs a large amount(above 10 kg or so), the character can be pushed through the walls and other objects. The second problem is that the camera doesn't always move in the direction you are faced. When you change directions, it takes varied amounts of time to turn which is a problem. I've been searching my code but I don't see why this is happening. There is one strange thing I can point out about my code however. Every time the computer checks for input, I also reset the force callback for the character's body. I haven't found a way around this unfortunately. It seems that I must reset the callback because otherwise when the body is at rest, newton does not use the callback. The only way I have found to make newton use this callback when the body is at rest is to reset the callback. I'll put the necessary code here:
//The force callback
void OnApplyForceAndTorque(const NewtonBody *rbody)
{
	dFloat mass;
	dFloat Ixx;
	dFloat Iyy;
	dFloat Izz;

	NewtonBodyGetMassMatrix (rbody, &mass, &Ixx, &Iyy, &Izz);
	dVector force (x_dir*mass, -mass * 9.8f+y_dir, z_dir*mass);
	NewtonBodySetForce (rbody, &force.m_x);
}

//The input code
void CharacterController::UpdateCamera()
{	
	//Store the old force values
        float tx_dir = x_dir;
	float ty_dir = y_dir;
	float tz_dir = z_dir;
	
	//Get rotation from mouse
	if(!PollM())
		return;
	yr+=GetMX()*0.2f;
	xr+=GetMY()*0.2f;

        //Check input
	if(key(DIK_W))
	{
		x_dir = sinf(D3DXToRadian(yr))*speed;
		z_dir = cosf(D3DXToRadian(yr))*speed;
	} else if(key(DIK_A))
	{
		x_dir = sinf(D3DXToRadian(yr-90))*speed;
		z_dir = cosf(D3DXToRadian(yr-90))*speed;
	} else if(key(DIK_S))
	{
		x_dir = -sinf(D3DXToRadian(yr))*speed;
		z_dir = -cosf(D3DXToRadian(yr))*speed;
	} else if(key(DIK_D))
	{
		x_dir = sinf(D3DXToRadian(yr+90))*speed;
		z_dir = cosf(D3DXToRadian(yr+90))*speed;
	} else
	{
		x_dir = 0.0f;
		z_dir = 0.0f;
	}

        //Check for jumping
	if(key(DIK_SPACE))
	{
		if(!space)
		{
			y_dir = 38.0f*speed;
			space = true;
		}else
		{
			y_dir = 0.0f;
		}
	} else
	{
		space = false;
		y_dir = 0.0f;
	}
		
        //Reset the callback
        SetForceCallback(body, OnApplyForceAndTorque);

        //Use the position of the body to set the view matrix
	SetAsView();
}


Any help would be very much appreciated!

Share this post


Link to post
Share on other sites

This topic is 3660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this