- Home /
platforme ...HELP!! POSITION ADDING
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!!
Answer by Michael CMS · Nov 06, 2012 at 09:03 PM
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;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Help With Add and Remove on a loop 2 Answers
Vector3 Transform.Position Not Working 2 Answers
How to stop transform movement at a certain point? 1 Answer
Acces to other object trigger thru other object script 0 Answers