- Home /
Movement with angle in 3d
I want to make my player dash in the direction of an angle to make him dash without changin where its facing so it doesnt disturb the movement and the player can aim forward while dashing backwards.
So first of all i want to use the angle to move the character in that direction.
angle = Mathf.Atan2(horizontalInput , verticalInput);
angle = Mathf.Rad2Deg * angle;
I stored the angle like this so i can use it to make the player move but i dont know how to.
Do i need to translate the angle into a vector3 or use a specific method or store the angle in a different way?
Answer by MusapKahraman · Apr 27, 2020 at 06:28 AM
@magarabozag1st You don't need to calculate the angle to move your player, in the first place. You have horizontal and vertical inputs. You can add these input as a vector2 or vector3 depending on your game. If you are developing a top-down game in a 3d space you can use the following code.
Vector3 input = new Vector3(horizontalInput, 0, verticalInput);
transform.position += input * speed * Time.deltaTime;
Answer by RaidingShaman · Apr 27, 2020 at 05:23 AM
Just do it:
Vector3 move = new Vector3( angle, angle, angle);
transform.Translate (move * speed * Time.deltaTime);