Jump to content
  • Advertisement
Sign in to follow this  

Character Controller Problems

This topic is 3996 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

        //Check input
		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
			y_dir = 38.0f*speed;
			space = true;
			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

Any help would be very much appreciated!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!