i have a platform thats parented to another game object and i have my player…so when the player is on the platform the platform move…but i found a way to make him move with the platform without getting parented…so i want to add the platforme position to my player position, well every position on every frame is adding position to my player…
i did that but i know its not good just to let u know what im trying to do
transform.position+=Platforme.transform.position; but it adding the hole position to my player… HELP!!
This is an expected behavior since you are the whole position to the current player position.
What you want is to update each frame the player’s position together with the platform (if he sits on the platform). This should be done from the platform’s script, since you want to move the player with the exact amount the platform moves.
Something like
class Platform : MonoBehavior {
public Player myPlayer;
...
void Update()
{
// calculate new platform position
Vector3 DeltaPosition = PlatformSpeed*TimeDeltaTime;
gameObject.transform.position = gameObject.transform.position + DeltaPosition ;
if (myPlayer.isOnPlatform)
myPlayer.transform.position = myPlayer.transform.position+ DeltaPosition;
}
}