- Home /
Question by
ghost20920000 · Jun 12, 2017 at 09:07 AM ·
rigidbody2dgravity
Rigidbody 2D Gravity Scale not working properly
I have it set where an object will fall if the player is within two positions, and it will rise again. if the player is not between the position the gravity is set to zero. It does fall and rise, but if i step out of the two positions, the object keeps on rising and doesn't stop. I am trying to recreate the rock boulder in mario that falls if the player is near. (Mass =1, Linear Drag = 0, Fixed Angle = Checked, Kinematic = NOT Checked, Interpolate = none, Sleeping Mode = Start Awake, Collision Detection = Continuous)
//the positions where gravity is set to zero
if (rockk.transform.position.y > 4.0 && player.transform.position.x < 59)
{
rockk.rigidbody2D.gravityScale = 0f;
a = 0;
}
if (rockk.transform.position.y > 4.0 && player.transform.position.x > 64)
{
rockk.rigidbody2D.gravityScale = 0f;
a = 0;
}
//go up , -1.2 is the ground
if (rockk.transform.position.y < -1.2 )
{
rockk.rigidbody2D.gravityScale = -1f;
}
//go down
if ( rockk.transform.position.y > 4.0 && player.transform.position.x >59 && player.transform.position.x < 64)
{
rockk.rigidbody2D.gravityScale = 1f;
a = 1;
}
Comment
Your answer
