Collisions

I am trying to create a function that will say “if object.x == -10” then " life = life - 1" How can I do this? [import]uid: 86506 topic_id: 14681 reply_id: 314681[/import]

Like this?

[lua]function hitBadStuff(obj)
if obj.x <= -10 then
life = life -1
end
end

hidBadStuff(obj)[/lua] [import]uid: 23693 topic_id: 14681 reply_id: 54307[/import]

I’ve got a routine that will calculate the exact distance between two objects regardless of the angle between them which is better if you’re not restricting your movement to just the x axis.
One thing that you need to know is the size of your objects.

[lua]local xdist=obj1.x-obj2.x
local ydist=obj1.y-obj2.y
if ((xdist*xdist)+(ydist*ydist)) <= 20 then – Check for collision.
life = life -1 – decrease life
end[/lua]

The figure 20 in line 3 above should be half the size of obj1 added to half the size of obj2, so if obj1 is 20 pixels wide and obj2 is 40 pixels wide then the figure would be 30.

Hope this is of some help. [import]uid: 7841 topic_id: 14681 reply_id: 54431[/import]