- Home /
Question by
Alpacaman · Jan 12, 2015 at 01:40 PM ·
2dcharactercontrollerrigidbody2d
Best way to move 2d rigidbody character
Hello. I'm testing out different ways to move a player-controlled character. This is what I'm using:
void FixedUpdate () {
float xmove = Input.GetAxis ("Horizontal");
rigidbody2D.velocity = new Vector2 (xmove*Movespeed, rigidbody2D.velocity.y);
I noticed that whenever it reaches maximum speed, the movement becomes jittery and not smooth. Is there a better way to move a character smoothly and SNAPPY?(like the one in Odin Sphere and Muramasa).
Comment
Answer by SnStarr · Jan 12, 2015 at 04:27 PM
private var speed : Vector2 = Vector2 (3, 0);
function FixedUpdate ()
{
rigidbody2D.MovePosition(rigidbody2D.position + speed * Time.deltaTime);
}
You can also throw in an if block something like this just to make sure he cant go over the max speed you set.:
float maxSpeed = 5;
float speed;
if(speed > maxSpeed)
{
speed = maxSpeed;
}
When I tried your solution, it worked great for moving my character in the X axis. But if there's input from the Y, it nearly freezes the fall speed, which is not very good!