transform.Translate is too smooth
I am currently working on a top down game and I am almost done with the character movement but I ran into a problem: transform.Translate doesn't stop immediately when I release the movement buttons. Instead, it slowly stops. I don't want this as I am going to add animations to my character and I don't want it to look weird when you want to stop moving. Here is the code I am currently using:
using UnityEngine;
using System.Collections;
public class CharacterController : MonoBehaviour {
Rigidbody Ridgidbody;
public float Speed = 1;
// Use this for initialization
void Start () {
Ridgidbody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
float Horizontal = Input.GetAxis("Horizontal");
float Vertical = Input.GetAxis("Vertical");
Vector3 Movement = new Vector3(Horizontal, 0, Vertical);
transform.Translate(Movement * Time.deltaTime * Speed);
}
}
I hope anyone knows an answer to my problem.
Greetings
Answer by Rob2309 · Apr 13, 2016 at 04:12 PM
The first thing I would change if you want frame prefect input, is to change Input.GetAxis to Input.GetAxisRaw... This prevents Unity from interpolating the input, which is most likely the reason why your movement does not stop immediately.
If that does not I help try removing the rigidbody if it isn't necessary...
Answer by felix11 · Apr 13, 2016 at 04:46 PM
I always like to do these things with the rigidbody: instead of : transform.Translate(Movement Time.deltaTime Speed); try: Rigidbody.velocity = (Movement * Speed);
Answer by b1gry4n · Apr 13, 2016 at 04:14 PM
change your speed variable from 1 to something like 5, 10, 15. The higher the number the faster it reaches its target, i guess you could say
I set my speed variable in the editor so this was not the case. Still thanks for answering!
Your answer
Follow this Question
Related Questions
Limit movement to just forward/backward and left/right 0 Answers
Rigidbody2D.MovePosition() doesn't do anything (but animations and transform.Translate() works) 0 Answers
Limit movement to just forward/backward and left/right 0 Answers
2D Using C# moving game object back and forth and random stop in between - all in x-axis 2 Answers
Diagonal character movement 0 Answers