Вопрос

I'm creating Unity2D runner where characters is running on the ground. I'm trying to force him run with constant speed by applying force with right vector but the movement is jerky.

I'm trying to achieve effect of endless run with permanent speed. It is easy in the air but works different (because of physics) when character is running on the ground.

Это было полезно?

Решение

  1. You could velocity and make sure to turn off gravity. If you are running on the ground make sure you turn this off.
  2. You could implement your own movement where you can update position depending on Time.deltaTime.
  3. Just use the built in character controller that unity comes with. basic directionals and jump. And mouse controls where the character faces.

EDIT:

  1. Use rigidbody velocity and turn off gravity and drag. This will keep your runner running forever.
  2. To implement this yourself. You can update the position of the object in the update method. Something like

    Vector3 temp = object.transform.position;
    temp.x = speed * Time.deltaTime;
    object.transform.position = temp;
    

    Where object is you runner and speed is how fast you would like him to move. This would be inside the update function.

  3. If you aren't going to be controlling the runner, dont bother with the controller

Другие советы

Use Rigidbody2D.velocity and pay attention to:

The velocity can also gradually decay due to the effect of drag if this is enabled.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top