playMaker

Author Topic: trouble with a 2d character controller[SOLVED]  (Read 1564 times)

ActionActaeon

  • Playmaker Newbie
  • *
  • Posts: 4
trouble with a 2d character controller[SOLVED]
« on: June 01, 2020, 04:08:04 PM »
I'm having difficulty with a 2d character controller.

I'm currently using the Get Axis and Add Force 2d actions to move around. The problem is that I add force infinitely and zoom off into oblivion. I would have thought the Float Clamp action would allow me to put a ceiling on my move speed, but I can't figure out how to properly implement that.

Previously, I was following some of the tutorials Hutong has posted, in which the Get Axis and Set Velocity 2d actions are used to move around. I liked how snappy that movement felt, but the problem is that the character sticks to walls as long as you continue to hold the input in that direction -- the person making the tutorial passes this off as a "surprise game mechanic," and doesn't show how to solve it.

I would appreciate any help I could get solving EITHER of these issues. Thank you!
« Last Edit: September 12, 2020, 12:33:36 PM by djaydino »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: trouble with a 2d character controller
« Reply #1 on: June 02, 2020, 02:13:12 AM »
Hi,

 you could set the velocity instead of adding force, then you would not increase speed as you add force.

The wall issue is unlikely due to setting the velocity, change the physics material of you wall to make it not sticky and that's it, also change the physics material of your player too.

 you can also cap the velocity by clamping it using Vector3ClampMagnitude for example.

Bye,

 Jean

ActionActaeon

  • Playmaker Newbie
  • *
  • Posts: 4
Re: trouble with a 2d character controller
« Reply #2 on: June 03, 2020, 01:07:35 PM »
Hi,

 you could set the velocity instead of adding force, then you would not increase speed as you add force.

The wall issue is unlikely due to setting the velocity, change the physics material of you wall to make it not sticky and that's it, also change the physics material of your player too.

 you can also cap the velocity by clamping it using Vector3ClampMagnitude for example.

Bye,

 Jean

Thanks, Jean! I'll give that a shot.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: trouble with a 2d character controller
« Reply #3 on: June 03, 2020, 02:17:53 PM »
You didn't say whether this is for a platformer. If you do something top-down, just ignore :)

I ran into so many issues with basic platformer-type movement in PlayMaker over time that I switched to scripting this particular system. Admittedly, some of that could be down to a slow notebook I used a while ago, but I did use pretty small and agile FSMs and yet there was always some annoying "lag". I could never get it to feel right (yes, I did test in builds). When there was no way to use the Input System, I eventually caved and scripted it. If you plan on a long game, I recommend that too. No regrets, it's great to be able to script some things now. There are some great resources out there for how to set up controllers and also complete scripts. (PlayMaker is still excellent for other things)

When you Set Velocity, you have the additional problem that it messes with the physics forces. If you have a simple platformer, this wouldn't be an issue, but it quickly becomes one when you want to use 2d physics (for momentum etc). So, for such cases, you have to "intelligently" switch states and carefully watch when Set Velocity is active (it's a very blunt tool, it just pastes over whatever the Rigidbody is doing). Especially watch out with overriding velocity Y. Many then wonder why their character doesn't get off the ground or behaves strangely in air.

The approach I use now is adding forces ~30ish and clamping velocity to something like 5. This allows to design the acceleration. I also once tried the Tween Action pack to accelerate using a curve (it's somewhere in the forum). That worked quite well, too.

There was no clamp velocity action at the time, so I made my own (I attach it below, but beware, it's just my own version I made back then). Just like with Set Velocity, you have to be very clear where it's active, but I think it should not interfere with physics forces acting on the rigidbody2D (needs to be tested).

If you use the old style Input Manager, I recommend using my GetAxisRaw action to fetch the axis. You also want to change the drag, and gravityscale values (for side-scrolling 2D).

There are some good tutorials on 2D Movement, among a lot of mediocre ones on YouTube. There's one decent one with Celeste style movement, but I found this one the best, and that one (however, ignore their ideas on momentum when turning: their approach doesn't actually work  :)).

Here are some links to my own (older) experiments with some example setups.
-- movement example with physics forces.
-- GetAxisRaw
« Last Edit: June 03, 2020, 02:19:59 PM by Thore »

ActionActaeon

  • Playmaker Newbie
  • *
  • Posts: 4
Re: trouble with a 2d character controller
« Reply #4 on: June 09, 2020, 01:27:50 PM »
Wow, thank you very much for the thorough and thoughtful response.  ;D I have a feeling I'll be unpacking all that over the next few days.