playMaker

Author Topic: 2D character crouching[SOLVED]  (Read 1945 times)

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
2D character crouching[SOLVED]
« on: October 14, 2020, 02:40:05 AM »
Hi.
I'm trying to make my 2D player to crouch when holding down key.

Animator
https://ibb.co/MZcxpyn

Action trigger (Playmaker)
https://ibb.co/fD3LNQJ

Crouch components (Playmaker)
https://ibb.co/Qd3P2FG


Basically, I want the player to crouch when holding down the "down-key". And when releasing, to stop crouching.

Animation: To play crouch animation when holding down key. And play Idle animation when releasing.

Physics: The player has two colliders, Circle Collider 2D and Box Collider 2D.
On holding down the down-key, the Box Collider get disabled (the top part).
I want to enable it again upon releasing the key - which it doesn't.

The crouch animation also does not stop upon releasing the key.

So my question is, how to get the character back to the initial state upon releasing the key?

Thank you for all your help in advance  ;D
« Last Edit: October 19, 2020, 07:08:46 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: 2D character crouching
« Reply #1 on: October 14, 2020, 05:15:22 AM »
Hi.
you need to set animator bool back to false when key is released.

also collider needs to be enabled again.

Btw you should minimize using Get/set Properties actions.

You can find actions to enable Colliders on the Ecosystem

Also you might be better off animating the collicer.
In an animation you can edit a box collider size / offset etc.
turning on/off colliders can have issues with triggers not detecting correctly.

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
Re: 2D character crouching
« Reply #2 on: October 14, 2020, 02:15:14 PM »
Hi.
you need to set animator bool back to false when key is released.

also collider needs to be enabled again.

Btw you should minimize using Get/set Properties actions.

You can find actions to enable Colliders on the Ecosystem

Also you might be better off animating the collicer.
In an animation you can edit a box collider size / offset etc.
turning on/off colliders can have issues with triggers not detecting correctly.

Thank you!!
I removed the collider by editing the crouch animation, that's was so much better!!

But I got stuck on how to make the character face the right direction while crouching (holding the down button + left/right).

Should I create an empty child object to the Player object - and then a new Playmaker FSM for the "facing"-direction? Or can I make this work in the same FSM?

This is how everything is set up now:
https://ibb.co/rwsVkks
https://ibb.co/tsfhzTZ
https://ibb.co/dWMyzYP

Any recommendations?  :(
« Last Edit: October 15, 2020, 02:11:27 AM by maxrostov »

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
Re: 2D character crouching
« Reply #3 on: October 15, 2020, 02:32:21 AM »
I tried this approach:
https://ibb.co/82rXQT3
https://ibb.co/NYv3Xqf
https://ibb.co/FhFkgLr

Now the character can only move left and right during the crouching animation (even without me holding down-key). So now the issue is that I can move left/right without the crouching...

What am I missing?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: 2D character crouching
« Reply #4 on: October 15, 2020, 10:16:05 AM »
Hi.
If you want the player not to move when crouch, Set the velocity x to 0 instead of the axis.

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
Re: 2D character crouching
« Reply #5 on: October 15, 2020, 01:18:38 PM »
Hi.
If you want the player not to move when crouch, Set the velocity x to 0 instead of the axis.

Hi! No, i DO want the player to move.

I basically have issues with making the player face the right direction while moving in crouch-mode.

I tried adding additional two "set scale"´s for the Crouch-state (like this: https://ibb.co/NYv3Xqf, https://ibb.co/82rXQT3).
But what happened instead was that the player started to crouch when moving normally (now he is only crouching when running left/right normally).

How can I make the player face the right direction when both running AND crouching?

PS: Thank you for helping me put, I really appreciate it. Hopefully someone will have use of this info as well.
« Last Edit: October 15, 2020, 01:57:49 PM by maxrostov »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: 2D character crouching
« Reply #6 on: October 16, 2020, 02:33:50 AM »
Hi.
Separate scale from movement.

Do the scale in a different fsm.

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
Re: 2D character crouching
« Reply #7 on: October 17, 2020, 11:44:02 AM »
Hi.
Separate scale from movement.

Do the scale in a different fsm.

Thank you. It worked!!

The last issue I have with crouching (hopefully):

- I've added a Ceiling Check on top of the player.
- And i've put all the "ceiling-objects" in a layer namned "ceiling".
So now if I release the "down button" when the player is under a ceiling-object - he remains crouching as he should.

But... if I move away from the object by pressing left/right (without holding the down key), the player will still be crouching even when there is no object blocking him from standing up.

How can I make the player to stand up automatically, as soon as there's no ceiling blocking?

I basically want the player to only crouch when holding key-down - the only exception is if there's an object blocking the player from standing up.

Here are my settings:
https://ibb.co/ZGSyn6R
https://ibb.co/nwDDkHH
https://ibb.co/MfrbVcq

Also (not sure if this problem is related):
If I press the up-key when the player is crouching under an object, the player stands up, and the body sinks in to the ground. Like this: https://ibb.co/chCkt3v
... I don't want the player to be able to stand up if under a ceiling-object.
« Last Edit: October 17, 2020, 01:57:09 PM by maxrostov »

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
Re: 2D character crouching
« Reply #8 on: October 18, 2020, 03:23:20 PM »
Issue solved.

I added a separate state that checks if bool-value is true/false.
If False (no ceiling), the state goes to Idle state. If true (there's a ceiling), the state waits until the bool-value is false.

If anyone has a similar issue in the future, see photo: https://ibb.co/xGfzLBY
Also, read the rest above.

Thank you Djaydino, you helped me a lot!  ;D
« Last Edit: October 19, 2020, 06:50:01 AM by maxrostov »