playMaker

Author Topic: How to make basic Hack&Slash movement with Playmaker ?  (Read 2865 times)

Bobyteal

  • Playmaker Newbie
  • *
  • Posts: 30
How to make basic Hack&Slash movement with Playmaker ?
« on: February 21, 2017, 04:24:44 PM »
Hi, I am boby, I am trying some basic movement with unity for a little hack and slash game. Any tutorials to propose ? Can't find any  :(

I would like my character to move where you click with the mouse, or if you want to constantly move in a direction hold the mouse button in a direction, just like in any Diablo game for example.

That would help me greatly for now ! ;)

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: How to make basic Hack&Slash movement with Playmaker ?
« Reply #1 on: February 21, 2017, 06:19:07 PM »
Quote
I would like my character to move where you click with the mouse

On left click of the mouse, you perform this: You get the position of the mouse click and assign it to a target position to a variable then you can use "transform look at" to face the direction of the target as a player. Then you apply "force forward" on the player of the target to get the player moving towards the target.

Quote
constantly move in a direction hold the mouse button in a direction, just like in any Diablo game for example.

This is very similar but instead of clicking you use hold down of the left mouse button


I found that the best way to either code or use playmaker is to think what you what to do, write it down, and do it step-by-step. Without thinking, designing and planning people end up with poor implementation or the lack of it :P
« Last Edit: February 21, 2017, 06:21:31 PM by elusiven »

Bobyteal

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to make basic Hack&Slash movement with Playmaker ?
« Reply #2 on: February 21, 2017, 08:17:36 PM »
Thanks man I will try it tomorrow as it is very late in my country right now ! Seems like the way to go.

And yeah thinking step by step is a good way to work, my problem is I don't know playmaker enough for now to do this as I lack the global understanding of what it can do and what it cannot do  ;D

Bobyteal

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to make basic Hack&Slash movement with Playmaker ?
« Reply #3 on: February 22, 2017, 05:02:50 AM »
Okay I think I am very close to the solution but I am stuck on a tiny problem.

I store the position of the mouse with 'Get mouse X' but it accepts only float, so I create a float variable. Then I use 'Look At' but it asks me a Vector 3 variable, I can't use my float variable.  :o

I have been looking for something to transform a float into a Vector3, at least just take the X out of it for the vector3 might be enough but I find nothing. Any ideas ?  :P

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: How to make basic Hack&Slash movement with Playmaker ?
« Reply #4 on: February 22, 2017, 07:39:05 AM »
Quote
I store the position of the mouse with 'Get mouse X' but it accepts only float, so I create a float variable. Then I use 'Look At' but it asks me a Vector 3 variable, I can't use my float variable.  :o

The reason it's a float is because Get Mouse X only gets the "X" coordinate on the screen. You need to use an action called "Get Mouse Position" to get all of them (x,y,z) , this will return a vector 3. If you don't have that action, get it from the playmaker's ecosystem.

If you don't have ecosystem, get it here:

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

Bobyteal

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to make basic Hack&Slash movement with Playmaker ?
« Reply #5 on: February 22, 2017, 10:00:59 AM »
Thanks, I didn't know it existed.

Well I am still running in a problem, GetMousePosition doesn't seem to work, that or MoveTowardsTo.

I feel like I am very close though, I took some screenshots from my Unity, maybe you can easily tell what is wrong !
http://imgur.com/a/tI4KO

Appreciate your help  :)

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: How to make basic Hack&Slash movement with Playmaker ?
« Reply #6 on: February 22, 2017, 10:15:40 AM »
Okay first of all, for debugging tick at the bottom of your state action window "Debug". This will display actual values of the variables under them. So you will be able to inspect values of the variables like positions etc.

On the top left of the playmaker editor Click on "Debug" and enable logging.

Now when you start the game, at the playmaker editor window at the bottom, you should have an option to "Open Log". This tool will allow you to inspect state by state what is going on with your FSM, it will also show you last assigned variables and you can move frame by frame by click next frame button on the top center of unity window.

Instead of manually sending events, you can also use a local event called "FINISHED" which by default transitions to next state when the current state fully finishes. Also untick normalize from mouse position. I would probably have to physically see the FSM/project to make it work, it's hard for me to make assumptions when I'm not at home.

Try playing with the debugging log window, it really helps and usually solves most of my issues because you can see what is going on in the FSM step-by-step.

Bobyteal

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to make basic Hack&Slash movement with Playmaker ?
« Reply #7 on: February 22, 2017, 01:47:57 PM »
Ok with the debug, I found that everything is working correctly except the state 'Move forwards to' which is broken, my character moves strangely and in the same direction no matter how different the Mouse Position is.

Screenschot : http://imgur.com/a/weCWk
The point you see on the scene is where he wants to go everytime I click, no matter how different the mouse position is between thoses tests.


EDIT: Actually I was wrong, the mouse position comes up with some crazy numbers. There is a problem here too, maybe the main problem actually.

« Last Edit: February 22, 2017, 02:01:12 PM by Bobyteal »

Bobyteal

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to make basic Hack&Slash movement with Playmaker ?
« Reply #8 on: February 22, 2017, 02:22:27 PM »
Oh I found something  :D
https://forum.unity3d.com/threads/recording-mouse-position-is-acting-weird.296044/

Now it moves a bit in the direction I am pointing at, but it's a tiny hiccup, I am using the "Screen To World Point" function to do the conversion of the mouse position given in pixels. It doesn't seem to work very well, must be related to the camera ><
« Last Edit: February 22, 2017, 02:35:46 PM by Bobyteal »

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: How to make basic Hack&Slash movement with Playmaker ?
« Reply #9 on: February 22, 2017, 07:22:14 PM »
Yeah the difference is because mouse is screen space, and it needs to be converted to world space. Another way would be to fire a ray.

http://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
http://docs.unity3d.com/ScriptReference/Camera.ScreenPointToRay.html