playMaker

Author Topic: Direction of collision  (Read 7081 times)

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Direction of collision
« on: September 13, 2016, 06:43:07 AM »
Is there any way to determine the direction from which the collision occurred?

For example, I have a room, I can enter it from the 4 corners of the world.
These rooms I put next to each other to form a labyrinth.

Now I have to type in every room in his FSMs that the entry was from the room A to room B. And such a combination is quite a lot.
More important this method is cumbersome in terms of further modifications my labyrinth, because I have to correct a lot of FSMs.

More convenient it would be to determine whether a entry was from the front, rear, left or right side of entered object.
Then I would have constant the FSMs and I could more freely move this blocks of my maze.
But how to tell which side was player enter to the object?

Maxi

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Direction of collision
« Reply #1 on: September 13, 2016, 02:05:30 PM »
Hi,

you could try to give every room a box collider which is a trigger. Then you could use 'Collision Event' and 'Get Collision Info' to determine the contact point in which the player hit the collider/ entered the room.

I hope this helps.

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Direction of collision
« Reply #2 on: September 13, 2016, 02:38:47 PM »
Thanks for the idea!
It seems to me that this will cause a problem.
Namely, when leaving the room I passed through the trigger that starts the event again.
But I need these triggers only when entering the room.

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Direction of collision
« Reply #3 on: September 13, 2016, 03:25:04 PM »
Maybe it something will help, if I say that the path always are arranged at an angle of 90 degrees.
So, the player always straightly moves parallel or perpendicular to the axes X or Z.

Maxi

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Direction of collision
« Reply #4 on: September 13, 2016, 04:00:34 PM »
Thanks for the idea!
It seems to me that this will cause a problem.
Namely, when leaving the room I passed through the trigger that starts the event again.
But I need these triggers only when entering the room.

You could set the collider-event to 'On Enter'.

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Direction of collision
« Reply #5 on: September 14, 2016, 02:43:59 AM »
I'm afraid that it will not help.
Please look at my picture.
If I will put 4 triggers, then every time when entering and exiting I'll be activated.
And I want to trigger an event only when entering the room.
That is why I am looking for a solution that will indicate the direction of a collision with an object.

Maxi

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Direction of collision
« Reply #6 on: September 14, 2016, 04:07:07 AM »
Hi,

I still think my idea works, you just need to make only one big collider for every room and then use the 'On Enter' mechanic of the collision event. This way it would only trigger if you enter the room.
I made you pictures also.

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Direction of collision
« Reply #7 on: September 14, 2016, 04:50:42 AM »
Thanks Maximilian!
It might work, I made a similar FSM,
but I do not know how you did variable for RommEnterPoint.
How did these coordinates?

I've created a variable, but do not have these coordinates.
And here's a little write about it, too little for me:
https://hutonggames.fogbugz.com/?W369


terri

  • Sr. Member
  • ****
  • Posts: 389
    • terrivellmann.tumblr.com
Re: Direction of collision
« Reply #8 on: September 14, 2016, 05:04:34 AM »
I would avoid using colliders, are you storing any info on the rooms, such as their X and Y positions within a grid? If you had that info on the room you're coming from and the one you entered, that'd be enough to know the direction

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Direction of collision
« Reply #9 on: September 14, 2016, 05:37:28 AM »
I don't record the positions of rooms anywhere. But I can do it.

I ask you for more information, which actions should I use?

terri

  • Sr. Member
  • ****
  • Posts: 389
    • terrivellmann.tumblr.com
Re: Direction of collision
« Reply #10 on: September 14, 2016, 07:47:38 AM »
Just compare the X and Y of the previous with the current room.

With the usual grid layout, if you are now at 1,2 and were at 2,2 that means you moved to the left, so you are at the right door.

Does that make sense? Obviously I don't know how your rooms are layed out, but if its a square with 4 possible door directions as it seems, then its simple.

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Direction of collision
« Reply #11 on: September 14, 2016, 08:28:04 AM »
Hi Terri! Yes, it probably is simple
and maybe even very simple! :-D

Unfortunately, I have never written programs, I never had to deal with the tools like Unity.
When came to me the idea for multimedia radio drama I was looking for tools and when I saw that there is such a thing as a Playmaker, where I can visually compose commands I was very glad. Oh, how I enjoyed in that time!
I also bought a Master Audio, which combined with Playmaker allows me to lay the bricks my world of sound.

And now I sit and scratch my head and probably soon I lose remains of my gray hair.
But I don't want to bore you the adventures of a man which has large eyes with astonishment ;-)

My rooms are square. Rooms and corridors I can sort out aligning to the grid.

That's what you're saying makes sense, but I do not know what actions to use, how to compose.
Can you give me another hint please?

terri

  • Sr. Member
  • ****
  • Posts: 389
    • terrivellmann.tumblr.com
Re: Direction of collision
« Reply #12 on: September 14, 2016, 10:35:53 AM »
There would be many ways to do it!

Right now you have big trigger that when you enter switches rooms, right?
So let's keep 2 variables: CurrentPosition and PreviousPosition
Everytime you trigger a switch, first set the PreviousPosition as the CurrentPosition, and then get the room's position and set it to the new CurrentPosition.

Now use get Vector3 XYZ and get the X of the Previous and Current Positions. Compare them with Compare Float. Here there are 3 possibilities: CurrentPosition's X is lower than PreviousPositions, so you moved Left. X is higher, so you moved right. X is the same, so you didn't move in the X axis.

If you didn't move in the X axis, do the same thing for the Y axis.

Make sure your triggers are aligned to a grid for this approach though.

Let me know if that gives you an idea of where to go. As I said, there would be many ways to do it, some are more complex but give you more to work on if you need it, but sometimes simple does it.

Also, bad news, the head scratching never goes away with this stuff!

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Direction of collision
« Reply #13 on: September 14, 2016, 10:58:20 AM »
Create 4 game objects with box colliders and make them a child of your room. Then add trigger events to all of them. When somebody enters the room one of your colliders will trigger. Make sure to create different event for each of them. And create a new state which deactivate all colliders after somebody entered the room to avoid collisions on exit. You can even create 5th child with box collider as big as room to detect when the guy will exit the room to activate wall colliders again.  Hope this helps.

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Direction of collision
« Reply #14 on: September 15, 2016, 04:39:49 AM »
Works perfectly.Thank you very much!
Activate Game Object action came in handy :-)

---

And thanks goes to Terri too.
Thank you for long and precise description.
But I used Masterr's way,
for me it was easier.
« Last Edit: September 15, 2016, 04:44:12 AM by Tomasz »