playMaker

Author Topic: Player rotate to facing moving direction  (Read 8399 times)

NuNuToGuru

  • Playmaker Newbie
  • *
  • Posts: 8
Player rotate to facing moving direction
« on: September 03, 2015, 11:09:11 AM »
Hello

Please forgive I try to look for and find many replies but it is hard to understand. I am new.

My player is controlled by arrows on keyboard to later mobile joystick but now arrows I can convert later. I want him to spin to look up when up arrow is pressed (he is walking up screen). Then look left when left arrow (he is walking left screen). So with this he will always be shooting forwards with facing at same angle. He look up bullets go up. Look right bullets go right.

Please help slowly. Steps by step.

thank you very much.

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Player rotate to facing moving direction
« Reply #1 on: September 03, 2015, 03:07:11 PM »
You didn't say if it was 2d or 3d-

If its 3d the common way to do it- is to get the input vector from the joystick/keyboard then then use a "look at direction" action and use that vector- then the player will always look in the direction they are moving-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

NuNuToGuru

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Player rotate to facing moving direction
« Reply #2 on: September 03, 2015, 07:36:57 PM »
It is a side looking 2d game but with objects of 3d  from Max for the look. sorry i am new. The Z blue arrow (move) is pointing away from camera.

Please say if I have correct:
Get input vector = 'Get Axis Vector' ? this will give me direction of move. I use this in 'Smooth Look At'. Smooth is better so player does not 'flip' but turns?


thank you for replying

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Player rotate to facing moving direction
« Reply #3 on: September 03, 2015, 09:08:14 PM »
Yes "get axis vector" is the correct action to use to get the Vector 3 variable that you then use with the "Smooth look at direction" and use that v3 in the "Target direction" field-

Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Player rotate to facing moving direction
« Reply #4 on: October 21, 2016, 09:23:56 AM »
I join to this thread, because I have done what is written here, but it's not working. My player does not rotate.
I have done something wrong, but I do not know what, if someone could look at my FSM and advice?


Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Player rotate to facing moving direction
« Reply #5 on: October 21, 2016, 05:27:23 PM »
I noticed a strange thing yet.
My player goes to point A, when I push arrow up.
And player can do only this movement.

After adding Get Axis Vector action the player additionally rotates when push arrow left or right.
How it's possible? Did I miss something?

Spunkyinteractive

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Player rotate to facing moving direction
« Reply #6 on: October 22, 2016, 12:49:36 PM »
Check out this video tutorial. This guy seems to be doing the same thing as you are asking about.

the movement fsm setup starts around the 5m mark.

-Stephen

Tomasz

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Player rotate to facing moving direction
« Reply #7 on: October 25, 2016, 05:57:15 PM »
Thanks a lot Stephen!
I sat and I analyzed and I finally watched what was wrong. Oh, how sometimes hard it is to learn ;-)
This tutorial gives me a clue. I had to correct spelling of my Horizontal Axis name and add the third axis for Z.
Now it's working, but I have another problem with this rotation.

For example:
My player should start to move to the selected object after the hitting the right arrow.
Before a player will start to move it rotates in a target object direction.
And it works beautifully.

But unfortunately now I can turn the player all the time during when he goes, but it should be blocked.
Only when the player reaches the target object I can press another arrow key and the player will go to another object.

Is there any possibility to block the arrow keys when a player moves?
Or maybe there is some other way to solve this problem?

Spunkyinteractive

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Player rotate to facing moving direction
« Reply #8 on: December 05, 2016, 08:59:01 PM »
Hey Tomasz,
Glad the video could help get you in the right direction.

There are plenty of ways you could block input until the player has finished moving.

One idea that comes to mind is to add another state with a 'trigger event' action. Add a collider to the target location and make it a trigger. Then you can have the 'trigger event' send an event so your fsm goes back to the state that allows for input again after hitting the trigger.

There are far more options too. I suggest playing around with various actions and looking through the wiki to see what actions might accomplish what you are looking for.

-Stephen