S
S
Stepan Savchuk2018-02-26 18:09:36
C++ / C#
Stepan Savchuk, 2018-02-26 18:09:36

Character in unity flies off stage?

I am learning the Unity 5 engine. When I insert the move script

public class FPSInput : MonoBehaviour {
  public float speed = 6.0f;
  // Use this for initialization
  void Start () {
    
  }
  
  // Update is called once per frame
  void Update () {
    float deltaX = Input.GetAxis ("Horizontal") * speed;
    float deltaZ = Input.GetAxis ("Vertical") * speed;
    transform.Translate (deltaX, speed, deltaZ);
  }
}

What could be the problem. I tried to attach a collider, is trigger - not set.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Gaydak, 2018-02-26
@Nikson_230

at least you need to multiply the delta on the update by Time.deltaTime - to make it smooth.
Otherwise, it turns out that you are attaching such a very sickly speed there.
https://docs.unity3d.com/ScriptReference/Time-delt...
read what it is.
well, so that it takes into account colliders correctly - Daniil Basmanov correctly advises you to move through physics
, but with huge values ​​\u200b\u200b- even an honest miscalculation will not help) "push" through the collider or begin to behave inappropriately

D
Daniil Basmanov, 2018-02-26
@BasmanovDaniil

Translate ignores colliders, if you want to move in physics use AddForce or MovePosition .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question