I don’t really understand how movement works in Unity. So, I want to make the characters eyes(which are spheres) move to the right when the player is moving right and vice versa. I tried this
void Update()
Whereas the velocity is being set in the player script in the update method as
float velocity = inputX * speed;
But it says the player script does not contain a definition for veloctiy. If I try speed it works fine, but that doesn’t help because speed is a fixed variable. I feel dumb for asking this, but how would i make it so the eyes move like 0.5 to the right when moving right, and 0.5 to the left when moving left?
Thanks
Easiest way to approach this is to just make an animation for the eyes, then trigger its condition(s) in code under the conditions of left or right. If the rest of your character has animations, it may be necessary to look into animation layers to isolate eye motion from other animation:
Oh okay, I will try an animation, thanks. But for future reference, how does basic movements work? I’ve done a million tutorials and I still don’t really understand transform.translate. How would you move something like 1 to the right with it?
Assume that object transform is deifned by four vectors. “Right”, “Up”, “Forward”, and “Position”.
Right/Up/Forward are directions, Position is position.
Those vectors in unity are “local X axis” is “Right”, “local Y axis” is “Up”, and “local Z Axis” is “forward”.
So. If you Pass in “Vector3(1, 0, 0)”, it will move one unit to the right (because “X” is “Right”) assuming object isn’t scaled.
If you Pass in “Vector3(0, 1, 0)”, it will move one unit up (because “Y” is “Up”) assuming object isn’t scaled.
If you Pass in “Vector3(0, 0, 1)”, it will move one unit forward (because “Z” is “Forward”) assuming object isn’t scaled.
If you pass “Vector3(1, 1, 0)”, it will move one unit to the right and one unit up.
If object is scaled, distance movement will decrease based on scale. If it is 50% of size, it will move 50%, if it is 200%, it’ll move 200%.
So.
Now, what does the line of code you tried in the beginning do?
transform.Translate(Vector2.right);
When triggered, on unscalled object it will make eyes jump out of eyesockets and move to point one meter to the right from original eye position.