- Home /
mid air controlling problem with rigidbody
Hello everyone! So im designing a game where i need to use a rigidbody caracter, because i want him to be able to walk on walls or cellings using costum gravity. I want a good old fashioned 8 Direction control i tought thats the best for my game. It will be a 3D platformer where the player needs to jump on small moving objects to proceed trough the level, so it needs to be precise. First i tried to move my player with AddForce but it isnt the way i want it because with AddForce the character first accelerates then deaccelerates which is bad because i cant move it on small surfaces. Then i tried with velocity change and it works because the player starts with full speed and almost stops immedatelly but then i encountered a problem : when i jump and want to controll the player its works fine but when the character starts to fall down the falling speed suddenly really slow and not realistic. if i jump and dont move evrithing is fine, but in midair controll the problem apears. Is somebody who is more experienced with a rigidbody character can help me out? Its driving me crazy for the past three days. Here is my code:
var direction : Vector3;
function FixedUpdate ()
{
var h : float = Input.GetAxis("Horizontal");
var v : float = Input.GetAxis("Vertical");
direction = Vector3(h,0,v);
if(Input.GetAxis("Horizontal") || Input.GetAxis("Vertical"))
{
rigidbody.velocity = direction * 10;
}
else
{
rigidbody.Addforce(Vector3.up * -10); //adding Gravity
}
if(Input.GetButton("Jump"))
{
rigidbody.velocity = Vector3.up * 20;
}
}
Thanks in Advice!
Thanks for your answer i mannaged to solve it Like you said :)
Answer by AlwaysSunny · Nov 24, 2014 at 12:28 AM
You shouldn't collect Input in FixedUpdate()
I think what you're describing is the expected behavior, because you're writing to the body's velocity with input instead of adding to it and clamping the result. Writing to velocity comes with its own set of problems.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can Someone help me with a script? (2D) 0 Answers
Character Controller Gravity 1 Answer
character joint scripting HELP!!! 1 Answer
character creation 2 Answers