+ 1
Unity c# simple movement cube(rotate with left and right arrow keys, move forward with up arrow key)like old resident evil ps1 ?
Unity c# how to rotate cube with right and left arrow keys on y axis. And move forward and backward with up and down arrow keys on cube's own axis. Like old resident evil ps1 games?
2 ответов
+ 3
Hello!
For unity related question I would suggest you to use the official unity forum: https://forum.unity.com/
As Unity Input System and other similar stuffs are proper of the Unity software more then related to the programming itself!
Good luck with your project!
+ 2
Edit:
This first part might already be done by default but encase it isn't:
Set up some input events that can run when a key is pressed.
Go to edit -> project settings -> input
Add some axes for arrow keys and give it some names such as, "left", "right".
Now, add a script to the object and test if the keys are pressed.
If the keys are pressed then rotate the cube.
Check if cubes are pressed with:
if (Input.keyDown ("left"))
// Start rotate to left animation
Check out:
https://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html
To rotate the cube:
Check out the slerp method in Quaternions.
https://docs.unity3d.com/ScriptReference/Quaternion.html
You can use this to smoothly rotate along some axis when the key is pressed.
Or,
You may be able to use something along the lines of this.transform.Rotate(Euler angle).
Hope that helps!