playMaker

Author Topic: How to make a Top Down Shooter movement  (Read 10272 times)

knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
How to make a Top Down Shooter movement
« on: June 01, 2017, 05:48:44 PM »
Hi everyone, I'm here to ask probably a very newbie question but I'm struggling a lot with this lately. I have tried a lot of stuff and I think I might be in the right track, but there's something missing. Basically, I'm trying to replicate the movement at the beginning of this video (and you can see the C# scripting process from minute 10 forward):
I already have the animator working with the Horizontal and Vertical axis. The only thing missing is changing animation with the character looking at mouse.

I could use the script he does but since we are using Playmaker all over our project I'd like to keep things clean and keep it this way.

Thank you in advance.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How to make a Top Down Shooter movement
« Reply #1 on: June 01, 2017, 07:09:46 PM »
Hi, Maybe you can use the "mouse look" action?

knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
Re: How to make a Top Down Shooter movement
« Reply #2 on: June 01, 2017, 07:20:14 PM »
Hi, my problem isn't with making the character look at the mouse. That part I can make work. My problem is joining the keyboard WASD + Mouse Look At and make it work in the Animator. I think this is called tank controls. It's a very used technique in top down shooters, where for example you are walking to the left using the 'S' key and looking backwards and the animation blends between the two (or something similar).

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: How to make a Top Down Shooter movement
« Reply #3 on: June 01, 2017, 09:22:35 PM »
Not sure if you are interested in third party, but opsive has a third person controller that includes top down plus look at mouse (including other things like crouch, jump, run, shoot, strife, etc). Animations included (although some you may want to replace a few). They have some basic playmaker actions for it, as well as I wrote a few more for it.

It has some basic inventory management, weapon switching (between primary and secondary), throwing abilities, single and double handed weapons for pistol and rifle, etc, built in IK, ragdoll wizard, etc.

https://www.assetstore.unity3d.com/en/#!/content/27438


knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
Re: How to make a Top Down Shooter movement
« Reply #4 on: June 01, 2017, 09:41:32 PM »
Not sure if you are interested in third party, but opsive has a third person controller that includes top down plus look at mouse (including other things like crouch, jump, run, shoot, strife, etc). Animations included (although some you may want to replace a few). They have some basic playmaker actions for it, as well as I wrote a few more for it.

It has some basic inventory management, weapon switching (between primary and secondary), throwing abilities, single and double handed weapons for pistol and rifle, etc, built in IK, ragdoll wizard, etc.

https://www.assetstore.unity3d.com/en/#!/content/27438

Hi, sorry, that's not what we are looking for. Our project is for learning purposes and doing games in the meanwhile. Thank you for your attention though! It looks really useful.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How to make a Top Down Shooter movement
« Reply #5 on: June 02, 2017, 04:37:16 AM »
To set parameters you can use the "Set Animator..." Actions.

Maybe this post on unity can help you out.
and i think there are some samples on the Ecosystem

knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
Re: How to make a Top Down Shooter movement
« Reply #6 on: June 02, 2017, 08:30:54 AM »
To set parameters you can use the "Set Animator..." Actions.

Maybe this post on unity can help you out.
and i think there are some samples on the Ecosystem

Did you see the YouTube video I referred to in the first post? He already does it in C# script. The only thing I need is for someone to shed a light on how I could make it on Playmaker. I'm getting very close. Take a look at this:

http://imgur.com/a/wGGS4

Now my problem is that the animations override each other and instead of the mouse replacing or blending with the keyboard one, it just doesn't play the animation. This happens because the Y values are similar.

knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
Re: How to make a Top Down Shooter movement
« Reply #7 on: June 02, 2017, 12:22:47 PM »
Ok, so I have tried to write the code on the video in order to try and learn what the guy did there. I managed to make it work and detected where the "magic" happens. It's here:

void ConvertMoveInput (){
      Vector3 localMove = transform.InverseTransformDirection (MoveInput);
      xAmount = localMove.x;
      zAmount = localMove.z;
   }

Basically he inverts the given amounts and converts to unique floats and then updates them in the animator, like this:

   void UpdateAnimator (){
      anim.SetFloat ("Z", zAmount, 0.1f, Time.deltaTime);
      anim.SetFloat ("X", xAmount, 0.1f, Time.deltaTime);
   }


Anyone knows how this could translate to Playmaker please? It would be great since in the project the other people don't know programming and I need them to be able to edit anything I do.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to make a Top Down Shooter movement
« Reply #8 on: June 03, 2017, 10:23:29 AM »
The key in there is InverseTransformDirection.

https://hutonggames.fogbugz.com/default.asp?W479

Inputs are basically relative to the camera, so you have to translate those to be relative to the character. The transform actions give you that.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
Re: How to make a Top Down Shooter movement
« Reply #9 on: June 03, 2017, 06:22:05 PM »
The key in there is InverseTransformDirection.

https://hutonggames.fogbugz.com/default.asp?W479

Inputs are basically relative to the camera, so you have to translate those to be relative to the character. The transform actions give you that.

Ok, almost there! Now the problem is that I don't know how to make Playmaker detect when to send this action when the values change.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How to make a Top Down Shooter movement
« Reply #10 on: June 04, 2017, 06:01:56 AM »
Hi,
You could use "Float Changed"
but i think it is better to use every frame and and set the animator float every frame.

knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
Re: How to make a Top Down Shooter movement
« Reply #11 on: June 06, 2017, 12:59:35 PM »
Hi,
You could use "Float Changed"
but i think it is better to use every frame and and set the animator float every frame.

Hello, still didn't manage to make it work. It's working right now half on Playmaker the other half with the script. Any way you guys could show me how to translate the below code to Playmaker FSMs (this is what's missing and I don't know how to translate and I have lost too many hours trying to)?

void FixedUpdate () {
      float horizontal = Input.GetAxis ("Horizontal");
      float vertical = Input.GetAxis ("Vertical");
      if (cam != null) {
         camForward = Vector3.Scale (cam.up, new Vector3 (1, 0, 1)).normalized;
         move = vertical * camForward + horizontal * cam.right;
      } else {
         move = vertical * Vector3.forward + horizontal * Vector3.right;
      }

      if (move.magnitude > 1) {
         move.Normalize();
      }

      Move (move);

      Vector3 movement = new Vector3 (horizontal, 0, vertical);

   }

   void Move(Vector3 move){
      if (move.magnitude > 1) {
         move.Normalize ();
      }

      this.MoveInput = move;

      ConvertMoveInput ();
      UpdateAnimator ();
   }
   void ConvertMoveInput (){
      Vector3 localMove = transform.InverseTransformDirection (MoveInput);
      xAmount = localMove.x;
      zAmount = localMove.z;
   }
   void UpdateAnimator (){
      anim.SetFloat ("Z", zAmount, 0.1f, Time.deltaTime);
      anim.SetFloat ("X", xAmount, 0.1f, Time.deltaTime);
   }

Pandur

  • Full Member
  • ***
  • Posts: 122
Re: How to make a Top Down Shooter movement
« Reply #12 on: September 16, 2017, 10:39:52 AM »
Same Problem for me... Inverse Transform direction will not the best way when you have a Controller with two float for a blend tree..

FrogP

  • Playmaker Newbie
  • *
  • Posts: 3
Re: How to make a Top Down Shooter movement
« Reply #13 on: September 28, 2019, 01:22:57 PM »
So has there been any tutorials anywhere for making the animations play relative to the direction the characters facing?

I have an 8 direction Controller only (no mouse but same problem) character, and in my mind it's simple, and in other engines I can do this. I'm new to Unity, and trying to reproduce the same effect in that,

You move with the left stick and face direction with the right stick.

Since I don't know what every playmaker ACTION does yet, it's hella lot of guesswork, and there's literally not a single tutorial on the entire web I could find anywhere showing how to do this. (Although thousands of tutorials showing how to look at a mouse pointer just sliding the character to face that direction).

If someone can aim me in the right direction for how to get the animations playing correctly when not always moving the direction the characters moving in, you would be very awesome! :) Thanks

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How to make a Top Down Shooter movement
« Reply #14 on: September 29, 2019, 10:48:52 AM »
Hi.
It kind of depend on how you need this,

But on the Ecosystem you have an action called : 'Get Axis Vector Extended' where you can get the Angle, maybe that can help to determine the direction.

Then you can use the angle and set a float in the animator with a 'Set Animator Float' action.

Then inside the animator you can use condition or maybe a blend to set the correct animation.

you could also use 2 x 'get axis' (horizontal/vertical) and use the 2 axis floats in the animator instead and check greater than / less than with 2 conditions.