IsCollisionBetween
From MaratisWiki
(Difference between revisions)
Dahnielson (Talk | contribs) |
Dahnielson (Talk | contribs) m |
||
(2 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | Example 1 : On collision between two objects, display "Collision detected" in maratis console window. | + | {{lua-function|isCollisionBetween|object1, object2}} |
+ | |||
+ | Return true if objects collided. | ||
+ | |||
+ | {{lua-function-param|object1|first object}} | ||
+ | {{lua-function-param|object2|second object}} | ||
+ | |||
+ | '''Example 1:''' On collision between two objects, display "Collision detected" in maratis console window. | ||
object1 = getObject("object1") | object1 = getObject("object1") | ||
Line 7: | Line 14: | ||
end | end | ||
− | Example 2 : On collision between two objects, play a sound | + | '''Example 2:''' On collision between two objects, play a sound. |
− | + | ||
− | + | ||
A = getObject("A") | A = getObject("A") | ||
Line 25: | Line 30: | ||
end | end | ||
end | end | ||
+ | |||
+ | The collision test is returning true when there is a collision, so since you objects are in collision you send a "playSound" order and the sound play from the beginning. | ||
[[Category:Lua scripting]] | [[Category:Lua scripting]] | ||
+ | [[Category:Lua function]] | ||
+ | [[Category:Physics]] |
Latest revision as of 00:27, 9 February 2014
isCollisionBetween(object1, object2)
Return true if objects collided.
-
object1
: first object -
object2
: second object
Example 1: On collision between two objects, display "Collision detected" in maratis console window.
object1 = getObject("object1") object2 = getObject("object2") function onSceneUpdate() if isCollisionBetween(object1, object2) then print("Collision detected") end end
Example 2: On collision between two objects, play a sound.
A = getObject("A") B = getObject("B") sound = getObject("sound") collision = 0 function onSceneUpdate() if isCollisionBetween(A, B) then if collision == 0 then playSound(sound) end collision = 1 else collision = 0 end end
The collision test is returning true when there is a collision, so since you objects are in collision you send a "playSound" order and the sound play from the beginning.