playMaker

Author Topic: How do I create a 2d movement loop?  (Read 583 times)

Swetech

  • Playmaker Newbie
  • *
  • Posts: 3
How do I create a 2d movement loop?
« on: August 02, 2021, 07:17:33 AM »
Hello everyone,

I am trying to make a simple 2d game where you move a cube within a box and collect items.

I am having trouble making my cube change direction the way I want it to.
It always starts of in the middle and moves to the right at a certain speed. This I have been able to accomplish.

However, after that I would like the cube (while continuously moving at that speed) change direction at a key stroke.

I am trying to construct and formulate the problem and it would look something like this:

-   If moving Right on X axis, then when (get key down) change direction to down on Y axis
-   If moving Down on Y axis, Then when (get key down) change direction to left on X axis
-   If moving left on X axis, Then when (get key down) change direction up on Y axis

Is am basically trying to create a rectangular movement loop but I cant seem to make it work.
Anyone have any idea of such a thing might be constructed? I am very much a noob at this but trying.

Thank you in advanced!

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 164
Re: How do I create a 2d movement loop?
« Reply #1 on: August 02, 2021, 07:41:03 AM »
Heya,

I'm guessing by your description you are using the same single key for input?

Do you want the cube to only move when the key is pressed or do you want key presses to simply change the direction of your cube?

I'm just trying to get a clear picture of the exact control method you're trying to achieve. :-)

Cheers,

Simon

Swetech

  • Playmaker Newbie
  • *
  • Posts: 3
Re: How do I create a 2d movement loop?
« Reply #2 on: August 02, 2021, 08:27:47 AM »
Hello,

Thank you for the reply.

I would like the cube to change direction only when you tap the key. Speed is constant.

I figured it would be easier if the cube always spawns in the middle and always starts its movement to the right on the X axis. That way the next tap of the key would make it go down on the Y axis and so forth.

I am trying to create a rectangular movement scheme which should look something like; Right - Down - Left - Up.

This change of direction is initiated by tapping a key.

RobotGoggles

  • Playmaker Newbie
  • *
  • Posts: 26
Re: How do I create a 2d movement loop?
« Reply #3 on: August 02, 2021, 09:26:51 PM »
Have you tried using the Axis Event action, then for each direction you can have a state which changes the velocity to a certain direction?
When life hands you insomnia, make video games.

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 164
Re: How do I create a 2d movement loop?
« Reply #4 on: August 02, 2021, 09:51:44 PM »
Hey Swetech,

I've created a very simple scene with an FSM that shows two ways you can tackle this issue. Both methods behave identically yet one is a brute force "visual loop" and the other is an elegant single state solution.



The key here is to use an array to store your 4 directions. Each time you press the space bar the array index is incremented by one.

Anyway have a play and let me know if you have any questions, always happy to help!  :)

Cheers,

Simon

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 164
Re: How do I create a 2d movement loop?
« Reply #5 on: August 05, 2021, 06:15:42 AM »
Hey Swetech,

How did you go with the example scene I made for you? Did everything work the way you wanted?

Swetech

  • Playmaker Newbie
  • *
  • Posts: 3
Re: How do I create a 2d movement loop?
« Reply #6 on: October 19, 2021, 07:43:38 AM »
Hello,

Sorry for the late reply!

Your example was perfect for what I needed.

It was a little disheartening looking at your FSM structure as it really hit home how little I actually know.

I made my own example, just to see if I could do it and it worked, in a fashion. But the comparison between yours and mine was like comparing a tent to a palace. They are both, in a technical sense a habitat, but the design and complexity miles apart.

I am still trying to understand why you have included some of the things you did, once again exposing the gulf in knowledge between an expert and novice.

As a quick follow up question. If I wanted to add a ray cast to my cube. Would I be better of using the “visual loop” FSM in your example? I’m thinking, that way I could add a ray cast in the specific direction the cube is moving, right, left etc. 

I really appreciate you taking the time and helping a beginner out. One of the major downsides, in my experience with using playmaker, is the sometimes lack of documentation. I often find an answer to a Unity coding question when using traditional C# script, but not so much when looking for the playmaker solution to the same problem. 

Besides this official forum, are there any other forums where one can go and ask playmaker related questions?

All the best
Swetech

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6474
    • jinxtergames
Re: How do I create a 2d movement loop?
« Reply #7 on: October 19, 2021, 11:27:16 AM »
Hi.
The Official forum is probably the biggest.

but you can join the Playmaker Discord Channel
Ecosystem might not work at the moment
here are direct Github Links to the custom actions :
https://github.com/PlayMakerEcosystem
https://github.com/jeanfabre


Join the PlayMaker Discord Channel!