playMaker

Author Topic: need help moving objects towards cursor  (Read 529 times)

jameshark

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
need help moving objects towards cursor
« on: April 14, 2018, 04:04:36 AM »
hey,

I'm still pretty new with playmaker and I've been having trouble for awhile now with trying to have a character fire ball objects towards where the mouse clicks on a 2D plane.

So far the objects will spawn where the character is. but I can't figure out a good method of having the balls fly towards the mouse. I've been using mouse pick on a plane object in the background to get a vector3 of where the mouse is, I've also been using a black star to represent where I've clicked which has been working.

But if I get the balls to move towards either the vector3 or blackstar object (using Move Towards) it will constantly return to a position in the middle no matter where I click.

I've attached footage of my problem and screencaps of my fsms, I appreciate the support I've had so far with playmaker on this forum, these are just problems I can't seem to wrap my head around.

https://www.youtube.com/embed/ZW4tdQwa3h4





djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3605
    • View Profile
    • jinxtergames
Re: need help moving objects towards cursor
« Reply #1 on: April 14, 2018, 11:40:20 AM »
Hi.
Maybe try setting the finish distance smaller on the move towards.

Also if the ball has a rigidbody (i can't see the inspector :) ), try to set gravity scale to 0 and see what happens.
and if you want some gravity you turn it up a bit and you can play around with the drag.

You shoul also look into using pooling, you can find some pooler actions on the Ecosystem

jameshark

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: need help moving objects towards cursor
« Reply #2 on: April 14, 2018, 04:29:19 PM »
hey thanks for replying,

I tried changing the finish distance to both 0 and 0.01 but it didn't change anything.

I added a rigidbody to the ball and changing the gravity scale to 0 would just make the ball go to the same place without falling, changing the angular or linear drag didn't seem to do anything either.

I'm wondering if it's something to do with either the vector 3 or plane, I think the balls are slighty changing position depending on where I click but still not towards either the exact position I clicked or blackstar.

And thanks, I will look more into pools.

jameshark

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: need help moving objects towards cursor
« Reply #3 on: April 14, 2018, 08:10:24 PM »
I believe I'm experiencing the same problem as the person in this post:

http://hutonggames.com/playmakerforum/index.php?topic=7883.0

unfortunately it's hard for me to understand what their solution was.

if anyone could suggest a method of having an object go towards where I click on a 2d plane I would greatly appreciate it, in the mean time I will continue to try finding a way myself.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3605
    • View Profile
    • jinxtergames
Re: need help moving objects towards cursor
« Reply #4 on: April 15, 2018, 11:21:14 AM »
Hi you need to use 'Mouse Pick 2D'
Then 'get vector 2xy'
get the x and y,
Then Set Vector3xyz
place the x and y variable and set z to the desired distance (z pos from your objects)
Now you can use this value to move.

or you could get my freshly made custom action "MousePick2dToVector3" on the Ecosystem


By the way you should use 'Set Fsm Vector 3' to set the value on the other object.
on a local variable.

You should avoid using globals for this, its a bad way of 'coding' and easy to hack (cheat)

i only use globals if i need to connect a prefab to another object when dropped in the game @ runtime.

jameshark

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: need help moving objects towards cursor
« Reply #5 on: April 17, 2018, 04:06:33 AM »
I tried your solution and it worked perfectly for an object that was loaded in the scene to begin with.

But when the ball objects are created from a prefab they'll permanently be stuck moving towards one direction no matter where I click.

The prefab ball and scene ball share the same Fsms, the difference is that the target object is selected from "Scene" for the scene ball, and "Assets" for the prefab ball. Using the Vector3 causes the same issue too.

I hope that makes sense, I thought I was so close to having this problem fixed.



jameshark

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: need help moving objects towards cursor
« Reply #6 on: April 17, 2018, 04:14:10 AM »
I think I found a new solution, instead of creating an instance from the prefabs I've started the scene with one instance of the Ball off-screen so that I can create duplicates of that object instead of the broken one from the prefabs.

so far it's working! thanks again for your help

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3605
    • View Profile
    • jinxtergames
Re: need help moving objects towards cursor
« Reply #7 on: April 17, 2018, 04:19:34 AM »
Hi,
Could you send me the prefab for testing?

it should work on a prefab also.

and happy to help :)

jameshark

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: need help moving objects towards cursor
« Reply #8 on: April 17, 2018, 04:47:19 AM »
hey, sure thing

https://drive.google.com/open?id=1v1ODtU0htpZOfhkb4wCMWCZwGdqaX09G

it has the prefabs for the 3 objects: the ball, player and target

those are the only ones in the scene I'm testing with