playMaker

Author Topic: Collision: How to detect collider position  (Read 3861 times)

Sly

  • Full Member
  • ***
  • Posts: 123
Collision: How to detect collider position
« on: August 23, 2014, 09:46:15 PM »
Hello,

I'm actually using the action Collision Event on my character, so I can know when a certain type of object is colliding with it.

When I know something is colliding, how I can detect in which direction the collider is? Is there a way to know if it's in front, back, left, right of my character?

Thanks

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Collision: How to detect collider position
« Reply #1 on: August 26, 2014, 07:58:50 AM »
You can use Get Collision Info. The direction is the Normal, its a normalized Vector3.

It's basically like 0,0,1 means forward, 0,1,0 means up, 1,0,0 means right, etc.
« Last Edit: August 26, 2014, 08:00:58 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Collision: How to detect collider position
« Reply #2 on: August 26, 2014, 09:48:01 AM »
Hello,

Thanks for your answer!

I'm actually feeling dumb because I never used Normalized Vector 3.  :-\
After having my normal vector3, how can I calculate the direction? By this I mean, ok 0,0,1 means forward, but how I determine that?

If my result is -0.593,0,0.99 for example, what I'm supposed to do with it, for find out my collision was forward and on the left too?

Sorry, it's a little bit abstract for me, so if someone can give me some explanations, it will be very appreciated. Thanks

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Collision: How to detect collider position
« Reply #3 on: August 26, 2014, 10:29:28 AM »
Well, you'll need to establish what "right" or "left" is, and what the tolerance is in numerical form. Off the top of my head I'm thinking that you could use a bunch of Vector3Compare actions to send events based on your specified tolerances of directions, but I'd be quicker to ask why you need to know which side the collision is on in the first place?.. Maybe there is a simpler approach.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Collision: How to detect collider position
« Reply #4 on: August 26, 2014, 04:00:29 PM »
Hello,

Ok, I'm giving you the situation.
Still in my top down view game, I made AI for my enemies. Actually I want them to react if an other enemy is colliding with them. So they will be able to move backward, or other kind of move.
But I need them to detect collision in front, in corner front right and in corner front left; and not in the back, corner back right and left.

Edit: I added a picture of what I need.
« Last Edit: August 27, 2014, 08:58:52 AM by Sly »

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Collision: How to detect collider position
« Reply #5 on: August 29, 2014, 09:21:26 AM »
Hello,

I try on my side and I have weird behaviour. I'm not sure to understand how to do that.

I actually follow your advice: I determine the Right and Left. Like On the picture I posted previously, I decide to only take care of the collision when it's on upper part of my character (Front right and front left) and ignore down collision

After that, I use ConditionnalExpression, so it's easy to calculate in one Box. If (X >= 0) && (Z <= 0) etc...
But my coordinate X and Z are weird. Sometime it work correctly, sometime it detect Left instead of right, or detect Right at the bottom...

I'am a little bit mixed up  :o Can you give me a concret example cause I'm not sure to understand exactly how to do that.

Phuzz

  • Full Member
  • ***
  • Posts: 101
    • Bzilla Games
Re: Collision: How to detect collider position
« Reply #6 on: August 30, 2014, 02:28:26 PM »
Hello,

Maybe this will help but in a  simpler form, in my breakout game i choose to control the ball left and right while hitting the battle by measuring the distance

On Collision Enter, get the distance between object and the X position of the paddle, if X is greater than 0 then its on the right side, and if Negative then its on the left side, i know this is simpler than what you need but might give you a hint.
Bzilla Games "Education with a Tickle!"
Qbucket Games "Voxel Games"