playMaker

Author Topic: Using collision enter for weapon hitting cube  (Read 6896 times)

joduffy

  • Full Member
  • ***
  • Posts: 121
  • Here to help
    • Online Playmaker Courses
Using collision enter for weapon hitting cube
« on: May 02, 2013, 10:36:35 AM »
Hi guys,

I am trying to get "on collision enter" to work in playmaker.
What I am trying to do is create a weapon that you can pick up. Then using the mouse button you can use it to hit a cube.

When the weapon hits the cube, the cube should detect the collision and destroy itself.

I have all the parts together and they all work but for one thing. I cannot seem to get the collision between the cube and weapon working.

I have tried using a combination of the following:
  • tags
  • collision boxes
  • is trigger enabled
  • rigidbody
  • trigger enter
  • collision enter

All to no luck. Can anyone tell me how they can get one gameobject to react to a collision from another gameobject. In my case it is a weapon hitting a crate. But it could be used many things like meteors hitting meteors and exploding.
- Jonathan

Online Playmaker Courses available at:
http://courses.jonathanoduffy.com

“I want the world to be a better place because I was here.”  -  Will Smith

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Using collision enter for weapon hitting cube
« Reply #1 on: May 02, 2013, 03:11:38 PM »
Hi,

 could it be that in the first place your two colliders are not set properly? one of them  must have a physics components, else triggers will not work.

bye,

 Jean

joduffy

  • Full Member
  • ***
  • Posts: 121
  • Here to help
    • Online Playmaker Courses
Re: Using collision enter for weapon hitting cube
« Reply #2 on: May 03, 2013, 11:04:26 PM »
Thank you for your reply Jean.

I have tried all of those combination. I attempted again today and got it to work.
Here is screenshots of the setup that is needed in case anyone else tries to do something similar.
What you need to do is:
  • make sure the trigger on the weapons collider is turned on. This is what will allow you to pickup the weapon. It is also used to trigger the crates destruction.
  • After the player has picked up the weapon you will need to add a rigidbody component to the weapon and disable gravity
  • on the crate you will need to detect for a trigger event.
  • I use a custom tag on the weapon to make sure nothing else sets off the crates destruction



I'm pretty sure I added a rigidbody to the weapon manually, but assigning it through playmaker works. Plus you don't set off the weapons trigger.

I do have one question. I know triggers are used in games for say invisible traps, turning lights on when you walk into a room, automatic doors etc and that collision detection is used to determine when two object collide eg cars crashing into each other in grand theft auto.

My question is how do you achieve this in playmaker. I have tried to setup both systems but to no avail. I know it might sound like a stupid question but I am just having some difficulties in implementing it.
- Jonathan

Online Playmaker Courses available at:
http://courses.jonathanoduffy.com

“I want the world to be a better place because I was here.”  -  Will Smith

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Using collision enter for weapon hitting cube
« Reply #3 on: May 07, 2013, 03:33:53 AM »
Hi,

 you can use the global events "ONTRIGGERENTER" and "ONTRIGGEREXIT" to transit to a state yntime something triggers your object, else you can use the action "TriggerEvent" in conjunction with "Get trigger info" if you need to only check for tagged gameObject, and/or do manual checks before an action.

 does that answer your questions? the rest is really about setting up your gameObject properly, that's outside playmaker. Do you have problem detecting triggers?

bye,

 Jean

joduffy

  • Full Member
  • ***
  • Posts: 121
  • Here to help
    • Online Playmaker Courses
Re: Using collision enter for weapon hitting cube
« Reply #4 on: May 07, 2013, 04:44:04 AM »
So in playmaker whats the difference between TRIGGERENETER and COLLISIONENTER
- Jonathan

Online Playmaker Courses available at:
http://courses.jonathanoduffy.com

“I want the world to be a better place because I was here.”  -  Will Smith

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Using collision enter for weapon hitting cube
« Reply #5 on: May 07, 2013, 06:36:52 AM »
Hi,

 this is unity Physics Terms actually.

Trigger: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html

Collider:
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html

you use colliders when your players hit a wall for example, and you use triggers to detect that your player entered an area. Triggers are usually invisible, Colliders are usually visible and represent physical obstacles. Triggers and colliders use the same component ( a Collider), only you can set a collider to be a "Trigger" using "is trigger" check box:

http://docs.unity3d.com/Documentation/ScriptReference/Collider-isTrigger.html

 Bye,

 Jean