Reputation: 1
I have trouble for getting collision in my game.
I have a physics room and some object. I have two objects where uses physics
is active.
I make them collide. and it's still ok.
But when I try to add some object without uses physics
in my room physics,
the two object before can't collide again.
If I remove the object without uses physics
, the two object before can collide again.
How to solve the 2 objects with uses physics
before. in order to be able collide as before, even though I add objects with non physics in my physics room.
I'm sorry for my bad english.
Upvotes: 0
Views: 2887
Reputation: 84
I don't think it is possible to detect a collision between a physics object and a non-physics object. However, what you could do is simulate a physics object to act like a non-physics object.
Enable use physics
for the non-physics object but manipulate it using the non-physics properties (e.g. vspeed, gravity, etc). Make it a Sensor so that it will trigger a collision without causing the other object to rebound. In the Step/End Step Event of the object, add the following GML code which will update the physics properties of the object based on any changes to the non-physics properties:
phy_fixed_rotation = true;
vspeed += gravity;
vspeed -= sign( vspeed ) * min( abs( vspeed ), friction );
hspeed -= sign( hspeed ) * min( abs( hspeed ), friction );
phy_speed_x = hspeed;
phy_speed_y = vspeed;
phy_position_x = x;
phy_position_y = y;
phy_rotation = -image_angle;
Now you should be able to move the object using non-physics properties, and hence collisions should be detected.
Upvotes: 1