Duplicate Question:
http://answers.unity3d.com/questions/1151064/how-to-reverse-a-sin-animation.html#answer-1151844
Reversing movement directions
So basically I'm trying to make two cubes move in opposite directions across a lane (obstacles for the player). I've managed to get the cubes to go right to left, but I need one to be going left to right to make them move in opposite directions.
This is what I've got so far: https://i.gyazo.com/6340d64be4f867e09b912d9b8ef0408f.gif
As you can see they both start in the centre of the lane and move right to left, I want the top one to be going left first, but I'm not sure how to achieve this. I created a seperate script and put everything in from the other script but I can't figure out what to change to make it go in reverse.
Here's the code on the cubes:
public class EnemyCubeMotion : MonoBehaviour {
float originalX;
public float floatStrength = 1; // Change x pos range in Editor
void Start()
{
this.originalX = this.transform.position.x; //Saving the original position
}
void Update()
{
transform.position = new Vector3(originalX + ((float)Math.Sin(Time.time) * floatStrength),
transform.position.y, //Sin between -1 and 1
transform.position.z);
}
}
If anyone could help me out or give me any suggestions I'd really appreciate it, I'm quite new to Unity so I'm making a lot of stupid mistakes at the moment. Thanks.
Follow this Question
Related Questions
Move 3D object on transform.localposition 1 Answer
Move a object along a vector 1 Answer
Moving GameObject a specific distance in the Z direction and back again - regardless of rotation 1 Answer
How to make an object move in the direction another object is facing on 2 axis? 1 Answer
Make character face movement direction 0 Answers