playMaker

Author Topic: Move Character - gravity ONLY during movement. Not when idle.  (Read 3644 times)

Qbanyto

  • Full Member
  • ***
  • Posts: 137
  • Vista Larga, Paso corto
Move Character - gravity ONLY during movement. Not when idle.
« on: September 02, 2020, 11:44:46 PM »
I’ve been solving many movement issues. But stumped on one.

So my character has a character controller.

If I’m in the air, he will just stay there. Floating basically.
But if I walk in any directions, THEN gravity kicks in and he falls down. 
The moment i stop walking, he’s back to “standing” in the air.

How can I have this gravity on all the time? I found a script online that supposedly fixed this. But haven’t tried it. Here is that scripts:

   var controller : CharacterController = GetComponent(CharacterController);
     controller.SimpleMove(Vector3.forward * 0);
 
  Any way to turn this into a playmaker way? Or should I just insert this script on the inspector?

Or better yet, how can I fix this issue?

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Move Character - gravity ONLY during movement. Not when idle.
« Reply #1 on: September 03, 2020, 11:21:28 AM »
You have to explain what you do. Do you change gravity scale? Do you have a move and a different idle state, and you overwrite (set) velocity in idle? Do you animate the root bone and your idle animation is misaligned etc?

Qbanyto

  • Full Member
  • ***
  • Posts: 137
  • Vista Larga, Paso corto
Re: Move Character - gravity ONLY during movement. Not when idle.
« Reply #2 on: September 03, 2020, 01:33:07 PM »
I did explain it.

I have an object with a character controller component.

the “Move character” action Applies the gravity automatically but only during movement. Not when idle

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Move Character - gravity ONLY during movement. Not when idle.
« Reply #3 on: September 04, 2020, 07:51:03 AM »
Okay, I see. You are using the component called CharacterController from Unity. The Unity description says this:

Quote
A CharacterController allows you to easily do movement constrained by collisions without having to deal with a rigidbody.

A CharacterController is not affected by forces and will only move when you call the Move function. It will then carry out the movement but be constrained by collisions.

So this means there is apparently no gravity, as it doesn't work with rigidbodies and physics. I don't know how the suggested setup works in this case, I only worked with rigidbody based movement.

Hasuman

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Move Character - gravity ONLY during movement. Not when idle.
« Reply #4 on: September 04, 2020, 01:15:11 PM »
Is there a seperate state for the "idle"? If it does, what actions are in there?

Qbanyto

  • Full Member
  • ***
  • Posts: 137
  • Vista Larga, Paso corto
Re: Move Character - gravity ONLY during movement. Not when idle.
« Reply #5 on: September 08, 2020, 08:47:07 PM »
ok I seem to have fixed this by using Controller Simple Move

 if i jump, on landing, he just falls through and keeps falling down to the shadow realm (lol).

one step forwards, two steps back. any ideas? I'll keep tinkering in the meantime.

I know Controller Simple Move ignores Y coordinates but he should stop when landing on the floor (like he did when I use "Controller Move".

Also I see it only happens if i jump in place. If I jump WHILE moving and continue moving, he won't fall through floor.

EDIT:

Seems to be a processing problem. If i plug in my charger to my laptop, the framerate increases and apparently the coding in unity gets better too because it doesnt  happen as long as my laptop is plugged in. this isn't good, what if someone plays my game without plugging in their laptop? I'll have to BUILD the game and test that out.

EDIT 2:
Yea he still falling through the ground when using simple move. Also I can’t control the air movement when jumping like I do with controller move.

I think this is more important to me. I need to figure out a way to constantly apply gravity while idle and going down slopes.

Simple move fixes all this but add the “falling through the floor” problem.
« Last Edit: September 09, 2020, 09:20:49 AM by Qbanyto »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Move Character - gravity ONLY during movement. Not when idle.
« Reply #6 on: September 09, 2020, 10:05:00 AM »
Can you double check that you use the character controller as intended? I have no idea about 3D, but your project sounds like it was a platformer or 2D. But in 2D, almost nobody uses the Character Controller.

I suggest you consider if this method with the Character Controller is the right approach for your project.

Qbanyto

  • Full Member
  • ***
  • Posts: 137
  • Vista Larga, Paso corto
Re: Move Character - gravity ONLY during movement. Not when idle.
« Reply #7 on: September 12, 2020, 05:29:58 PM »
I should of specified :p

Yes it’s a 3D platformer like Mario 64.

Can you double check that you use the character controller as intended? I have no idea about 3D, but your project sounds like it was a platformer or 2D. But in 2D, almost nobody uses the Character Controller.

I suggest you consider if this method with the Character Controller is the right approach for your project.

Qbanyto

  • Full Member
  • ***
  • Posts: 137
  • Vista Larga, Paso corto
Re: Move Character - gravity ONLY during movement. Not when idle.
« Reply #8 on: September 14, 2020, 08:21:01 PM »
I'm wondering if i should have like a downwards movement if "onGround" variable is false.