Im beginning in Unity, Im doing a FPS. I have two separate arms with no animations. The thing is that I would like to simply rotate or translate thoses arms every time im moving to make it look like an animation. How could I simply make this script. Im using the FPSController so I guess I should call this script( the moving arm script ) in FPSController every time I press A,W,S,D or arrows.
I dont know where to begin with.
Please gimme a hand
Though I doubt you’ll get good looking results this way (as in: it will look very statical), here’s some things you might find helpful:
To catch input from the A,W,S,D keys and arrows, you want to use Input.GetAxis(“Horizontal”) and Input.GetAxis(“Vertical”). The horizontal axis will react when A, D, Left or Right is pressed. The vertical axis reacts when W, S, Up or Down is pressed. You can find this in your Input Manager, there the primary and secondary keys for both axis are declared. The way this works: both axis contain a value between -1 and 1, when nothing is pressed the axis’ value is 0, when you press either it’s “positive button” or “alt positive button”, it quickly goes towards 1. When you press the axis’ “negative button” or “alt negative button”, it goes towards -1.
To adjust an object’s rotation there are a few things you could use. You’ll probably want to use transform.Rotate() or transform.RotateAround() which rotates around an axis (x, y or z). You could also manually adjust an object’s rotation by using it’s transform.EulerAngles or transform.Rotation (though this is a quaternion and these can be quite hard to work with if you don’t understand how they work)
Just in case you didn’t know this yet, something really helpful when you start programming in Unity is the Unity Script Reference. This is an overview of (nearly) all classes and their functions, variables, …
If you’re really knew to Unity, try following one of their tutorials, you’ll probably find the Lerpz tutorial quite helpful to understand the Unity basics.
That’s about all I can think of at the moment. I hope it helps
Here is what I have so far, a single Arm rotating over and over. How can I stop this arm from rotating over and over. I should use a lerp but duno how to use it well.
Here is my script:
public class LeftArmRotate : MonoBehaviour
private Vector3 depart;
void Start ()
depart = transform.position;
void Update ()