- Home /
How can i make my player stick with moving platforms?
Hi, i'm making a side-scroll game and i have a problem , i made a moving cube that moves up and down, but the problem is that my player not standing on that cube while it going down cuz its faster then the gravity force, and while the cube is going up the player can't even stand on it cuz it actually avoiding the player.... i don't know what to do..
this is the script i used for the cube
void ProcessState()
{
if (transform.position.y >= -43)
{
Down = true;
Up = false;
}
if (transform.position.y <= -130)
{
Down = false;
Up = true;
}
}
void Move()
{
if (Down)
{
transform.position += Vector3.down * Time.deltaTime * moveSpeed;
}
if (Up)
{
transform.position += Vector3.up * Time.deltaTime * moveSpeed;
}
}
Answer by roamcel · Aug 05, 2011 at 09:40 AM
I believe that it's not the cube's script at fault, but rather your player's one.
There might be a logic flaw in here in fact:
1- gravity is -naturally- faster than a platform, so your player SHOULD fall faster, and thus not suffer from this issue. FIX: apply a GRAVITY variable modifier to your character 'falling' vector.
2- if you want to ATTACH the player to the platform, regardless of gravity and such, use a COLLIDER. When the platform collides and the collider info is the player, make it so that on the 'Update' of the platform, the coordinate of the player is the one in your 'player attach empty object', which you child to the platform, with a boolean variable telling if the player is in the platform or not, so that you can detach him when he jumps or moves away from the collider trigger. I however discorage this approach lol.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
My GUI stopped working? 2 Answers
I can only move left and right with a bluetooth controller, but when wired, it works just fine. 0 Answers
Can't use wasd control in game! 1 Answer