- Home /
Problem with diagonal movement
Hello, so I have this problem with diagonal movement. I wrote this code and I don't know why my objects are moving diagonally.
public class Movement : MonoBehaviour
{
public float speed;
private void Update()
{
Vector3 v3 = Vector3.right;
transform.Translate(speed * v3 * Time.deltaTime);
}
}
Is it a bug?
no bug.
the transform is moved right. it's either a different script messing with it or the camera does not look film the front and it appears to be diagonal.
translate is to translate a world direction to a local object. One common reason is that objects imported from blender are on a different XYZ axis, leaving us with childing blender objects to empty gameobjects to re-orient them.
It's moving right but also it's moving back because value of x is increasing and value of z is decreasing and I want to understand why it happens using only Vector3.right
Just stop using translate and move them based on their own transform.right. Transform.translate is kind of a terrible way to move objects, unless circumstantially.
Answer by Games_20 · Dec 16, 2018 at 02:59 PM
@hexagonius I wanted to move the object diagonally but I didn't expect that when I used only "Vector3.right" the object would change x and z axes.
Your answer
Follow this Question
Related Questions
moving and rotating my object in 3d 1 Answer
Player moves diagonally even when not telling him to 0 Answers
Smooth touch for map 0 Answers
What is the algorithm to assign to transform.right? 1 Answer
Create variable based on local axis 1 Answer