playMaker

Author Topic: 'Move Towards' while respecting collisions  (Read 5745 times)

VectorF22

  • Junior Playmaker
  • **
  • Posts: 50
'Move Towards' while respecting collisions
« on: May 29, 2015, 08:31:06 AM »
I'm having trouble finding a solution to my simple problem.

I'm trying to make an object's position move towards a destination vector3 position (that could also be moving) every frame while respecting the collisions.

Anything I have tried either doesn't allow the location to be calculated every frame (by using a moving Vector3 destination), or it completely ignores any kind of collision and passes straight through other objects to get to the destination.

Any ideas?

Thanks!

VectorF22

  • Junior Playmaker
  • **
  • Posts: 50
Re: 'Move Towards' while respecting collisions
« Reply #1 on: May 29, 2015, 10:06:26 AM »
http://hutonggames.com/playmakerforum/index.php?topic=2253.0

The touch3ddrag sample on this topic is essentially what I'm trying to achieve, only with collision detection too. If you put another cube in that scene with a collider, the cube you're moving will go straight through it because the Set Position action overrides any collision that may be occurring.

Tedthebug

  • Playmaker Newbie
  • *
  • Posts: 21
Re: 'Move Towards' while respecting collisions
« Reply #2 on: May 29, 2015, 06:36:03 PM »
Does the object that's moving have a rigid body?  Have you tried using navmesh?

I also did something similar to what I think you want with the enemies looking at the object then movetowards each frame.  They had rigidbodies & normal colliders with no trigger.

VectorF22

  • Junior Playmaker
  • **
  • Posts: 50
Re: 'Move Towards' while respecting collisions
« Reply #3 on: May 30, 2015, 02:19:35 PM »
Yeah it has a rigid body...

Essentially all I'm trying to do is move a cube via the touch screen, only I want the cube to not be able to go through other walls.

Setting the position of the cube to be the position of where the player is touching seems to completely override any collision detection that may be taking place. I've tried using physics to add force towards where the player is touching, but that seems to make the cube go all crazy and shakey when it's trying to go through the wall.

VectorF22

  • Junior Playmaker
  • **
  • Posts: 50
Re: 'Move Towards' while respecting collisions
« Reply #4 on: June 01, 2015, 10:50:39 AM »
The solution was as simple as I thought it would be!!
(after already spending hours looking into overly complicated other solutions of course...) -_-

In the playmaker EcoSystem there is another action called "Move Towards Advanced". It's exactly the same as the standard move towards action, only this allows you to set the update type...

All you need to do is set the Finish Distance to 0 so that it calculates on every frame and never actually finishes, then set the Update type to "On Fixed Update" so that it calculates along with all the other physics calculations. And that's it!

You now have an object that will always move towards something else but won't pass straight through the collisions.
« Last Edit: June 01, 2015, 10:52:17 AM by VectorF22 »