playMaker

Author Topic: Activate physics when the player approach [SOLVED]  (Read 2147 times)

Megisto

  • Playmaker Newbie
  • *
  • Posts: 28
Activate physics when the player approach [SOLVED]
« on: March 18, 2013, 07:45:54 PM »
I'd like to activate the physic of some objects when the player approach to them and deactivate the physic when the player go far.

I tried with a sphere trigger collider that follows the player and two state for the object that must be awaked (sleep > on trigger enter > awake), but it doesn't work. It seems that i can detect when the trigger event enters but i cannot detect when it exits.

Some good advice? thx
« Last Edit: March 18, 2013, 09:11:52 PM by Alex Chouls »

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Re: Activate physics when the player approach
« Reply #1 on: March 18, 2013, 07:58:06 PM »
That's odd. 

Make certain that the objects you want to register with the trigger have both a trigger volume and a rigidbody attached. 

I can't think of a reason why it wouldn't detect an exit event though, if it successfully detects entry.

You could also try "TriggerStay".


Megisto

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Activate physics when the player approach
« Reply #2 on: March 18, 2013, 08:08:41 PM »
Oh, ok. Both of them must have a rigid body attached! Now it works.

Thank you

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Activate physics when the player approach [SOLVED]
« Reply #3 on: March 19, 2013, 01:34:53 AM »
Hi,

 stay away from triggerstay :) I am doing poetry now :)

but honestly, this is the biggest source of bad performance you can get with physics. Instead prefer hosting one fsm on the gameobject that listen to enter and exit and maintain a flag.

 there is only one case where I have to use trigger stay, it's when you instantiate an object and you can not control where it will be in the world and therefore can be instantiated ALREADY colliding with another object, in that case, you will not get the TriggerEnter call from unity...

bye,

 Jean