- Home /
Character Control General Issues
I do not want to use the character controller that comes with unity because i want to learn how to do this myself. I have about three issues (This is first person game btw):
1) My character accelerates exponentially, just going faster and faster until i stop pressing the forward button. How can i setup a max speed?
2) Fixed
When i look down and move forward i don't move forward, this gets worse the further i look down.
3) How do i go about making my character accelerate faster?
I have googled this but the usally say things like "use the unity character controller" or are in C#.
//Players Abilities
var playerSkill_strafeSpeed = 10;
var playerSkill_walkSpeed = 15;
//Player Moving around
function FixedUpdate ()
{
if (Input.GetButton('player_forward'))
{
rigidbody.AddForce(transform.forward * playerSkill_walkSpeed);
}
if (Input.GetButton('player_back'))
{
rigidbody.AddForce((transform.forward * playerSkill_walkSpeed) * -1);
}
if (Input.GetButton('player_right'))
{
rigidbody.AddForce(transform.right * playerSkill_strafeSpeed);
}
if (Input.GetButton('player_left'))
{
rigidbody.AddForce((transform.right * playerSkill_strafeSpeed) * -1);
}
}
Answer by NickP_2 · Feb 05, 2014 at 10:17 AM
If you modify the 'drag' property in the rigidbody's inspector, the air resistance will be modified. The larger the number, the more air resistance.
What does this do? I'm not a physicist, but I noticed the larger the drag, the longer it takes for an object to reach his max speed. Sow hen you modify the drag, the object will start slow, and accelerate until a certain speed is reached.
This isn't easy to control tho
Hope this helps :)
Thank you for answering, the objects drag was currently on 0 and i want to increase the acceleration. Yes you are right but doing that for this object wont work. (Unfortunately setting it to negative numbers doesn't work.)
the answer is no longer needed because i have figured it out and my code is now very different
The code is very different because it now takes input from joysticks
var Rotation_Speed: float = 60;
var Speed_Forward: float = 30;
var $$anonymous$$ax_Speed_Forward: float = 5;
var $$anonymous$$ax_Speed_Backward: float = -5;
var Centre_Of_$$anonymous$$ass: float = 0;
function Start ()
{
//Set the centre of mass
rigidbody.centerOf$$anonymous$$ass = Vector3 (0, Centre_Of_$$anonymous$$ass, 0);
}
function FixedUpdate ()
{
var rotation = Input.GetAxis("Horizontal_Legs") * Rotation_Speed * Time.deltaTime;
transform.Rotate(0, rotation, 0);
if (((Quaternion.FromToRotation(transform.forward, Vector3.forward) * rigidbody.velocity).z < $$anonymous$$ax_Speed_Forward) && ((Quaternion.FromToRotation(transform.forward, Vector3.forward) * rigidbody.velocity).z > $$anonymous$$ax_Speed_Backward))
{
var forward = (Input.GetAxis("Forward_Legs") * Speed_Forward) * -1;
rigidbody.AddForce(transform.forward * forward);
}
}
Your answer
Follow this Question
Related Questions
AI movement using Character Controller, turning problem 1 Answer
character turning problem! 0 Answers
CharacterController unexpectedly moving up 0 Answers
How to move player with xbox controller 1 Answer
Pick-Up Object With Mouse Hold 0 Answers