Gamespace: Moving End Platform (Movement)
I wanted my last platform to move and say the word 'FINISH' so that the player knows where the end of the landscape is.
Platform Moving Away |
Platform Moving Closer |
This was the inspector for my moving end platform.
The Script 'Moving End Platform' has been attached to it.
The Vector 3 variable 'initialPosition' is set to private so that it cannot be changed in the inspector.
Moving End Platform Inspector |
The Vector 3 variable 'initialPosition' is set to private so that it cannot be changed in the inspector.
The 'initialPosition' variable is assigned to the object's location using 'transform.Position' in the Start() function.
In the Update() function, the position of the platform is set using the initial position of the platform (using the variable 'initialPosition') plus the new 3D vector where the X-axis is equal to zero, the Y-axis is equal to zero and the Y-axis is equal to a Sin wave multiplied by three to make the wave bigger. This moves the platform continuously on the Z-axis.
Comments