playMaker

Author Topic: Changing animation based on mouse position/distance of player  (Read 1751 times)

Sickpuppet

  • Playmaker Newbie
  • *
  • Posts: 2
Is it possible in Playmaker to track mouse cursor position and distance from your player character in a 2d game?

Something like the old game Wild Guns but a bit more advanced. Control the character to move left or right with A and D etc, and aiming your gun with the mouse. Not talking about rotating anything. I want Melee weapons as well but they wouldn't need to be mouse tracked so just talking about the guns I guess.

For example, you aim your mouse at a nearby distance in the upper left side of the character then it plays the animation idle of aiming your gun at the nearby upper left side. Then you move your mouse further away to the upper left and then it plays the animation idle of aiming your gun at the far upper left. Finally you press the left mouse button and it plays the animation of the far upper left gun fire. same for all 8+directions.

All the examples I have seen just talk about rotating a sprite to face the mouse cursor which isn't what I want. So I'm curious if this is possible in playmaker, thanks!
« Last Edit: April 28, 2017, 07:44:02 PM by Sickpuppet »

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Changing animation based on mouse position/distance of player
« Reply #1 on: April 28, 2017, 09:21:21 PM »
Playmaker has a mouse pick action, which saves the vector, speed, object it is touching, etc (raycast). Then you get the vector of your player. With those two numbers you can figure out the distance. This can even then tell you if your mouse is above, below, left or right of the character by looking at the X, Y numbers, and whether they are positive or negative.

With those numbers in mind, you can make them into floats. There is a playmaker action for this as well.

Then do a float switch. Basically if the number is between is below -10, do this event. If below -5 do this event. If below -1, do this event, etc. (Such as change animation).

There is nothing that you said that I can see, that couldnt be done in playmaker.

Then use the mouse click event to fire off your shots (which would trigger another animation, or effects).

Sickpuppet

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Changing animation based on mouse position/distance of player
« Reply #2 on: April 28, 2017, 09:29:51 PM »
awesome thanks for the reply! I was hoping it was doable I just haven't seen anyone mention it before, just how to rotate a sprite at the mouse like for top down shooter games.

Does it matter if there is scrolling or if the camera is static? I'm pretty sure i'd keep it static, but I'm curious if it makes a difference if there is scrolling through a level if that affects the x y vector coordinates tracking or not for this kind of feature?


tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Changing animation based on mouse position/distance of player
« Reply #3 on: April 28, 2017, 09:44:34 PM »
It shouldnt be hard, using the same method, long as the player is fixed to the camera with the scroll. Ie, when the character moves, then the camera moves. That way, his local vectors in relation to the mouse should remain the same.  8)