Time.deltaTime problems
Im new to coding so I apologize if this sounds ignorant... But im trying to multiply my move speed with time.deltatime and it stops my player from moving entirely. From my understanding it just multiplies my speed by a factor like .1 making it 1/10 as fast but at a set time thats independent of framerate, correct? If i remove time.deltatime my character moves, add it it doesnt. Im aware fixedupdate is set but I seen someone say do deltatime anyway but ive tried both fixedupdate and just update and it does the same thing... I just started this script about 20 minutes ago so its still premature;
public class Movement : MonoBehaviour
{
Rigidbody2D rb2d;
public float horizontalMovement = 0f;
public float movementSpeed = 80f;
public float jumpForce = 60f;
// Start is called before the first frame update void Start()
{
rb2d = GetComponent();
}
private void FixedUpdate()
{
float horizontalMovement = Input.GetAxis("Horizontal") * movementSpeed;
rb2d.velocity = new Vector2 (horizontalMovement * Time.deltaTime, 0);
}
}
Answer by rage_co · Sep 19, 2021 at 06:08 AM
you don't need to use Time.deltaTime in fixed update, in fact you shouldn't, it makes it frame rate dependent since fixed update is already frame rate independent, so simply remove it...and just for information, if you do want to know the delta time between two fixed updates..use Time.fixedDeltaTime....and also Time.deltaTime just gives 1/framerate...so its usually 1/150 something
Thank you very much for your response. Thats what I thought and had even tried fixeddeltatime but it was doing the same thing. And had tried changing fixedupdate to just update and it was still making things odd. But I will stop using delta time in fixedupdate thank you.
Your answer
Follow this Question
Related Questions
I have a walljump script but the walljump doesn't work right can someone help me? 0 Answers
Stop movement on collision 1 Answer
how to move a gameobject based on a dice roll 1 Answer
Prevent rigidbody from sticking to wall? 0 Answers
How do I add two different values from a script on seperate game objects? 0 Answers