playMaker

Author Topic: Collision and Detection Problem {Solved}  (Read 6640 times)

Lostcity

  • Playmaker Newbie
  • *
  • Posts: 31
Collision and Detection Problem {Solved}
« on: May 15, 2014, 08:45:52 PM »
Sorry to bother you guys again. I've gotten more and more familiar with Play-Maker over time but I have 1 problem that is preventing me from moving forward with my game. I'll try to explain them them as clearly as possible:

Problem-Enemy Detection: My enemy does not seem to be detecting my Player (FPS controller prefab). I've experimented with this problem for a long time and can't figure out what I'm doing wrong. In particular, I need my enemy to damage my player upon collision with "Player" tag.

Currently my enemy prefab has a box collider and a rigid-body. The Damage Player FSM is set up like this:

-Enemy FSM-

State 1: Collision Event with "Player" Tag. Send event Collision enter

State 2: Wait (1 sec). After wait time transition to State 3

State 3: Here is where the actual damage happens using an Int Add value of -20 to a global variable int.

My Player is only equipped with the player controller (though I've tried adding colliders and it still didn't work). The Player Health FSM is set up like this:

-Player FSM-

State 1: Set Int Value (Global Var int), Set GUI text, Convert Int to String.

State 2: Int Compare: If equal or less than 0, transition to "death" State. If greater than 0, do nothing.

I'm not sure why my enemy doesn't recognize my player. I'm also having a problem getting my enemy to follow my player.
« Last Edit: May 16, 2014, 07:05:17 PM by Lostcity »

dottim

  • Playmaker Newbie
  • *
  • Posts: 7
  • lost in space
    • The Quantum Principle
Re: 2 small problems
« Reply #1 on: May 16, 2014, 10:18:21 AM »
problem 1: I think it's trigger event you need to use if want two colliders to detect each other (with triggers set on the collider and my objects also have rigidbodies, set kinematic if you want their colliders to be able to overlap) and use the correct tag on the trigger event


problem 2: I manually set all my variables to the correct start values in a seperate fsm after death, you have to do it this way I think to 'reset' the values

Lostcity

  • Playmaker Newbie
  • *
  • Posts: 31
Re: 2 small problems
« Reply #2 on: May 16, 2014, 12:17:02 PM »
problem 1: I think it's trigger event you need to use if want two colliders to detect each other (with triggers set on the collider and my objects also have rigidbodies, set kinematic if you want their colliders to be able to overlap) and use the correct tag on the trigger event


problem 2: I manually set all my variables to the correct start values in a seperate fsm after death, you have to do it this way I think to 'reset' the values

Thanks for the help. I tried your method for the first problem but now my player goes through my enemy.

As for the second problem, its now solved ;D

I made an empty game object called Var manager and used an Int Set Value action for the global variables that needed to be reset on start.
« Last Edit: May 16, 2014, 01:12:08 PM by Lostcity »

Lostcity

  • Playmaker Newbie
  • *
  • Posts: 31
Re: 2 small problems
« Reply #3 on: May 16, 2014, 03:08:38 PM »
Both of my issues are now solved and I can (finally!) move forward with my game. Just in case anyone else runs into these issues here is the solution:

-How to Reset Global Variables-

Global variables are a powerful tool but the main drawback is that they only load once. So in my case I had a clock that would count down every second and when the clock hit 0 it would be game over. However, when I tried to restart the game, my clock timer would not reset. Therefore, I'd get an instant Game Over (which doesn't make for a very fun game).

To fix this: I created an empty game object called Variable Manager. The Variable Manager has one FSM with one state. Here is how the state is set up:

State 1: Set Int Value (choose global variable int and input the starting value). I have 1 Set Int Value action per Int variable.


-Problem with collision events-

Unity has a pretty picky collision system when it comes to sending events. However, the Unity staff was nice enough to make a table to show what colliders work with others.

The table is at the bottom of this page: (http://docs.unity3d.com/Documentation/Components/class-MeshCollider.html)


Thanks everyone for their help. Hopefully this thread will be of use to someone else in the future.

Justin Q.
« Last Edit: May 16, 2014, 07:17:10 PM by Lostcity »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Collision and Detection Problem {Solved}
« Reply #4 on: May 20, 2014, 10:02:13 AM »
Hi,

 you can't reset variables. what you did id the right way. You can then make a global event or some logic to com back to this state if you want to reset it.


thanks for the link on the collision matrix, definitly helpful!

bye

 Jean