- Home /
I got a code that isn't normalized. Can someone help me?
here's my code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Move : MonoBehaviour { Vector3 Position = new Vector3(1.0f, 1.0f, -25.0f); const int SPEED = 5; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update()
{
if (Input.GetKey("w"))
{
Position += new Vector3(0, SPEED * Time.fixedDeltaTime, 0);
}
if (Input.GetKey("s"))
{
Position += new Vector3(0, -SPEED * Time.fixedDeltaTime, 0);
}
if (Input.GetKey("a"))
{
Position += new Vector3(-SPEED * Time.fixedDeltaTime, 0, 0);
}
if (Input.GetKey("d"))
{
Position += new Vector3(SPEED * Time.fixedDeltaTime, 0, 0);
}
transform.position = Position;
}
}
What is the exact question here?
The code you have should work.
Answer by ShadyProductions · Jun 20, 2018 at 05:38 PM
Naturally Time.fixedDeltaTime is the difference between two calls of FixedUpdate() and it always holds the same value.
As you see, it would make no sense using Time.fixedDeltaTime in the Update() method. Better use Time.deltaTime instead in Update(). Time.deltaTime is the time interval between current frame and the last one, which is the same than the time interval between two calls to the Update() method.
Ok, I get it. so after i change Time.fixedDeltaTime to Time.deltaTime, how would I normalize the speed?
You don't need to, but if you have to:
new Vector3(SPEED * Time.deltaTime, 0, 0).normalized;
I think it works but I can't tell cause now it's going extremely fast.
Your answer

Follow this Question
Related Questions
Sprite size as a fraction of Viewport size 0 Answers
How to lower float value A as float value B gets bigger? 1 Answer
Direction from two objects 1 Answer
Custom Mesh Vector3's not normalizing 2 Answers
Problem Solved [JS] 1 Answer