#ground detection not working UNITY3D

1 messages Β· Page 1 of 1 (latest)

slender ravine
#

always apply gravity, even if the player is on the ground

modest quest
#

the gravity is a acceleration force

modest quest
slender ravine
#

get the remaining velocity after moving and set the velocity to that. if you're on the ground, it will be 0.

modest quest
#

its 4 am what

slender ravine
#

actually no, it doesn't seem to do that

#

i guess just use a rigidbody and add forces manually

modest quest
#

and i found a thing that was bothering me

slender ravine
#

i never seen anyone actually use it for that

modest quest
slender ravine
#

also, i don't use unity, so maybe i'm just being dumb

modest quest
slender ravine
#

sorry

modest quest
#

yea

#

ground detection not working UNITY3D

slender ravine
#

looked it up again and it looks like the leftover velocity is set automatically

#

so you should always be applying gravity

#

not all of the code is shown but from what i see it looks like currentGravity is remembered across updates

#

don't do that, just add to velocity

#
// The class
private Vector3 velocity = Vector3.zero;

// ...

Vector2 moveDir = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));

velocity.x = moveDir.x;
velocity.z = moveDir.z;

velocity.y += -9.81f * Time.deltaTime;

characterController.move(velocity * Time.deltaTime);
#

actually no, you do have to set the y velocity to 0 when grounded

modest quest
slender ravine
#

you need a rigidbody if you want to slide off

modest quest
#

are there any better solutions to fix the isGrounded properity WITHOUT using rigidbody?

slender ravine
#

that is grounded, it’s just that charactercontroller won’t do sliding, only your movement from code

modest quest
#

i don't use the isGrounded anywhere else

slender ravine
#

charactercontroller only moves in one direction and stops when there is a collision. it doesn't slide.

modest quest