Detect specific object collisions

I am making a racing game, i would like to make it so there are parts on the track which slow you down (like oil spots) My only thought is that i would need to write some code that will detect when collision happens between my character object and that oil spill object. How would i go about coding this, i have only figured out how to detect global collisions? also if anyone has a better idea of how to accomplish this any comments are welcomed, thank you [import]uid: 19620 topic_id: 6938 reply_id: 306938[/import]

give each item a [lua].type[/lua] variable (or [lua].name[/lua] or whatever you want to call it) then in your collisions check the type of each object

[lua]if(event.target.type==“car” and event.other.type==“oil” then)[/lua]

an example of this is in the “DragPlatforms” included sample [import]uid: 6645 topic_id: 6938 reply_id: 24340[/import]

ok ill give it a look, thanks! [import]uid: 19620 topic_id: 6938 reply_id: 24353[/import]

Ok so i think i have it coded somewhat close to how it needs to be, i at least am not receiving errors, but nothing happens when my two objects collide, here is what i have:

--My Tire Object  
  
local tireObject = display.newImage("tire.png")  
tireObject.type = "tire"  
physics.addBody(tireObject, { friction= 50, bounce= 0, radius=25, density = 1 } )  
  
--Booster Object  
  
local booster = display.newImage( "boost.png" )  
booster.width = 50  
booster.height = 25  
booster.x = 1531  
booster.y = 184  
booster.type = "boost"  
  
--Then my function that allows you to jump only when you are --collided with the ground, i added my other collision code --here, hope its right...  
  
function onLocalCollision( self, event )  
 if ( event.phase == "began" ) then  
 total\_collisions = total\_collisions + 1  
 end  
 if(event.target.type=="tire" and event.other.type=="boost") then  
 tireObject:applyForce(60,500, tireObject.x, tireObject.y)  
  
  
 elseif ( event.phase == "ended" ) then  
 total\_collisions = total\_collisions - 1   
 end  
end  
  
--TOUCH DOWN LISTENER  
tireObject.collision = onLocalCollision  
tireObject:addEventListener( "collision", tireObject )  
  

So am i doing the .type part of my code correctly? also my booster does not have physics applied to it, does it need to in order for the collision to fire? thanks for the help [import]uid: 19620 topic_id: 6938 reply_id: 24679[/import]

Ok i just tried it adding physics to my boost object and making sure that it is set as a Sensor and it worked!! sweet! if anyone else is having trouble with this please post and ill see if i can help also [import]uid: 19620 topic_id: 6938 reply_id: 24680[/import]

I have copy and paste your collision example to my app and still not working… I have try to put a print( “aaaaaa” ) to see if the if between the 2 objects is working but i dont get a return of “aaaaa” in terminal…

if(event.target.type=="bomba" and event.other.type=="cauldron") then  
score.setScore( score.getScore() +5)  
print ( "aaaa" )  

this is my IF between objects… anyone have a idea?? [import]uid: 23063 topic_id: 6938 reply_id: 36356[/import]