Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: RedOni on June 12, 2017, 01:21:46 PM
-
I'm not sure if that was clear enough, so let me explain.
I have a 2D side-scroller set up with a crosshair (tied to the mouse) for the player to aim projectiles with. The problem is, it's using a ITween Move To with a Vector3, so the crosshair determines where EXACTLY it'll go and how fast it'll get there. I want my projectiles to travel at a set speed, and only travel in the direction that it's aimed at, not the exact position of the crosshair. Any ideas how I'd set that up?
-
Hi,
you can determine a direction vector by substracting the target with the player position, this will give you the direction.
then instead of using iTween, I would simply use translate action like so:
-- normalize the direction ( so that the direction magnitude is 1)
-- instantiate your projectile at the player position ( or gun position)
-- translate your projectile of the direction * Speed
Does that make sense?
Bye,
Jean
-
Hi,
you can determine a direction vector by substracting the target with the player position, this will give you the direction.
then instead of using iTween, I would simply use translate action like so:
-- normalize the direction ( so that the direction magnitude is 1)
-- instantiate your projectile at the player position ( or gun position)
-- translate your projectile of the direction * Speed
Does that make sense?
Bye,
Jean
They won't travel towards the crosshair now. They seem to want to move towards one fixed point in the scene, despite the fact that the Vector3 is constantly updating.
EDIT: Nevermind, it's almost working. I don't see how to add speed to the "Translate" action though, there's no option for it.
-
Hi,
The "speed" for translation is how much you move on frame or per seconds ( which is better for consistency across devices), and so as I mentioned in the post above, to translate an object at a given speed, you need:
The direction vector ( normalized, so that it's magnitude is 1), multiplied by the speed factor ( a float that you define in an fsm variable).
If you need a quick sample let me know.
Bye,
Jean
-
Hi,
The "speed" for translation is how much you move on frame or per seconds ( which is better for consistency across devices), and so as I mentioned in the post above, to translate an object at a given speed, you need:
The direction vector ( normalized, so that it's magnitude is 1), multiplied by the speed factor ( a float that you define in an fsm variable).
If you need a quick sample let me know.
Bye,
Jean
That would be helpful, thank you.
-
I wrote a handy custom action. You can find it at the end of this thread. http://hutonggames.com/playmakerforum/index.php?topic=15212.msg70397#msg70397
You give it the start position and the target. Check the box "normalize", and you can get the normalized direction.
Just take that normalized direction and multiply this variable (normalize direction) by your desired speed.