playMaker

Author Topic: Newbie Question: Detecting Collisions  (Read 5911 times)

Red

  • Hero Member
  • *****
  • Posts: 563
Newbie Question: Detecting Collisions
« on: May 27, 2011, 01:57:05 PM »
Okay... so, i've read through this subforum, checked the reference manual but for some reason i've tried the "collision event" on a bullet prefab to test what it's colliding with (so i can allocate damage, change animation, etc...) but i don't seem to understand what's going on here.

i've told it to call the "collision detected" event and threaded that FSM up to it like all the tutorials say for handling FSMs.

and i've also tested that the delete fsm works (alt+click while running)

i just can't seem to get it to work. (i'm sure i could find a workaround but this seems like something i would need to know how to use properly.)

any tutorials or anything out there to point me in the right direction? it just doesn't seem to be detecting the event... (do i have to set a trigger object in there somewhere? i ask this because i had thought that unity's default colliders were meant to handle that kinda thing.)
« Last Edit: May 27, 2011, 02:19:22 PM by Red »

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Newbie Question: Detecting Collisions
« Reply #1 on: May 27, 2011, 06:58:47 PM »
From the first time I've noticed this "behavior" I've realised it'd be an endless source of grief for beginners. OnCollision and OnTrigger actions don't warn you that you need a rigidbody attached to the object. Simply adding the collider, as logical as it might seem, doesn't work. You need the rigidbody. If you want it to not really collide with anything and just work as a trigger, you still need the rigidbody, just with gravity off and iskinematic toggled on - that'll make the rigidbody not interact with physics at all.

That's probably (I can't remember tbh heh) Unity's standard behavior and not a Playmaker's fault, yet Playmaker should give the alert message of a missing component when these actions are added to any FSM.
--
Breno "MaDDoX" Azevedo
@brenoazevedo

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Newbie Question: Detecting Collisions
« Reply #2 on: May 27, 2011, 07:05:03 PM »
oi, thank you very much. it was driving me a little batty (since i had thought that it was something i was doing wrong.)

LordShaggy

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 50
Re: Newbie Question: Detecting Collisions
« Reply #3 on: May 29, 2011, 09:56:35 PM »
Rigid bodies should only be applied if you want the object to be effected by physics.   Otherwise, a collision event will go off.


Experiment a few things for me Red.


-Create a sphere
-Add a sphere collision to it
-Add a FSM on it
-Create 2 states
-One state with a global transition (if you dunno how to do that watch the tutorial www.digitalwarlords.com)
-Make that global transition OnCollision.
-Make another transition in that state (finished)
-Link that back to the starting state.   *As like an idle sit*
-Create another sphere with a collider put nothing on it.
-Start the scene, click on the sphere that has the FSM move so that it hits the other one and watch the FSM inside of it.

That will give you an idea.  The problem I am seeing is your using the Action "Collision detected"  instead of the natural  ONCOLLISION event that will happen in the FSM of the object that a collision occurs.

Things like


FINISH
ONTRIGGER
ect...

All those premade events are automatic events that are called out inside of the FSM whenever they happen to the object the FSM is sitting in. 

 

LordShaggy

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 50
Re: Newbie Question: Detecting Collisions
« Reply #4 on: June 09, 2011, 11:26:30 AM »
Did this help you red ?

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Newbie Question: Detecting Collisions
« Reply #5 on: June 14, 2011, 09:01:54 AM »
yep, figured it out. had a bit of a headscratcher from trying to figure out which global transition you meant (i used collision enter since the collider would be entering the space of the other collider it would be interacting with.) but i got it working.

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Newbie Question: Detecting Collisions
« Reply #6 on: June 15, 2011, 09:18:22 AM »
The problem is that the built-in events (the CAPS ones) are fired during any collision. Collision event is based on tags and as such is much more efficient. You also have to consider that sometimes you're always "colliding" with something, if you've got a large volume working as a boundary, for instance. Of course there are ways around it, like using the new Unity "layers" feature, but it's a constant source of grief for novices.

As for the need of a rigidbody, yeah it's a Unity thing. If you have a collider and no rigidbody, you have what Unity calls a "static collider", something you shouldn't move or you'll get a huge performance penalty. Collisions always need physics to happen anyways. For triggers, when you check the "isTrigger" option in the collider the physics engine completely ignores it, so there's no performance penalty even with a rigidbody attached. You can read more about it here:

http://unity3d.com/support/documentation/Components/comp-DynamicsGroup.html
--
Breno "MaDDoX" Azevedo
@brenoazevedo