playMaker

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

knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
    • View Profile
How to make a Top Down Shooter movement
« on: June 01, 2017, 02: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): https://www.youtube.com/watch?v=F5a4Xo6ijLE

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: 2288
    • View Profile
    • jinxtergames
Re: How to make a Top Down Shooter movement
« Reply #1 on: June 01, 2017, 04:09:46 PM »
Hi, Maybe you can use the "mouse look" action?

knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to make a Top Down Shooter movement
« Reply #2 on: June 01, 2017, 04: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

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: How to make a Top Down Shooter movement
« Reply #3 on: June 01, 2017, 06: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
    • View Profile
Re: How to make a Top Down Shooter movement
« Reply #4 on: June 01, 2017, 06: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: 2288
    • View Profile
    • jinxtergames
Re: How to make a Top Down Shooter movement
« Reply #5 on: June 02, 2017, 01: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
    • View Profile
Re: How to make a Top Down Shooter movement
« Reply #6 on: June 02, 2017, 05: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
    • View Profile
Re: How to make a Top Down Shooter movement
« Reply #7 on: June 02, 2017, 09:22:47 AM »
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: 2484
  • Yup.
    • View Profile
    • Cleverous
Re: How to make a Top Down Shooter movement
« Reply #8 on: June 03, 2017, 07: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.

knownasa

  • Playmaker Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to make a Top Down Shooter movement
« Reply #9 on: June 03, 2017, 03: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: 2288
    • View Profile
    • jinxtergames
Re: How to make a Top Down Shooter movement
« Reply #10 on: June 04, 2017, 03: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
    • View Profile
Re: How to make a Top Down Shooter movement
« Reply #11 on: June 06, 2017, 09:59:35 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.

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

  • Junior Playmaker
  • **
  • Posts: 82
    • View Profile
Re: How to make a Top Down Shooter movement
« Reply #12 on: September 16, 2017, 07: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..