- Home /
Question by
NinjaRubberBand · Feb 19, 2014 at 12:41 PM ·
vector3gravity
OncollisonEnter2D does not work on moving object
I have a scene with a floor and a ceilling. Then i have a player which is a cube. When i click with my mouse, it changes the gravity so that i can walk on the ceiling. When i click again then i fall to the floor, and can walk on the floor.
While you do this, some different obstacles will come flying at you. Some of these "obstacles" there will come flying at you you can walk on. Like if the ceiling and floor turns to spikes, you walk on a long cube in the middle. But i have found out, that the player does not get affected by the gravity when standing on a moving object. How do i fix this, or is there a other way to do it?
var press : boolean;
function FixedUpdate()
{
if(Input.GetMouseButtonDown(0) && press == true)
{
Physics2D.gravity *= -1;
press = false;
}
}
function OnCollisionEnter2D(coll: Collision2D) {
if (coll.gameObject.tag == "bars")
{
press = true;
}
}
Comment