#Fixing Some Character Glitches

1 messages · Page 1 of 1 (latest)

covert marsh
#

ok again. putting that type of ground checking is unreliable

#

here is how Unity does it in their example assets. very basic , DONT JUST COPY IT.. LOOK WHAT ITS DOING AND WHAT FIELD YOU NEED.

    Vector3 spherePosition = new Vector3(transform.position.x, transform.position.y - GroundedOffset, transform.position.z);
            Grounded = Physics.CheckSphere(spherePosition, GroundedRadius, GroundLayers, QueryTriggerInteraction.Ignore);```
#

meant to be studied and looked at ^^ should be easy to implement

#

Grounded is a simple bool as normal but it directly returns from the physicsSphere

#

remove the Oncollision enter and leave first

#

thats just gonna cause more issues

#

no you dont need those two functions

#

remove them entire

#

from 55 to 75

#

replace it with that GroundCheck() method

#

did you delete from 55 to 75 yes?

#
private void GroundedCheck()
        {
            Vector3 spherePosition = new Vector3(transform.position.x, transform.position.y - GroundedOffset, transform.position.z);
            Grounded = Physics.CheckSphere(spherePosition, GroundedRadius, GroundLayers, QueryTriggerInteraction.Ignore);
#

add this new method

visual arch
#

he means, remove this one and make a new method GroundCheck

    void OnCollisionEnter(Collision other)
    {
        if (other.transform.tag == "Ground")
        {
            IsGrounded = true;
        }
        else
        {
            IsGrounded = false;
        }
    }

    private void OnCollisionExit(Collision collision)
    {
        if (collision.transform.tag == "Ground")
        {
            IsGrounded = false;
        }
    }
visual arch
covert marsh
#

now put GroundedCheck(); in your update

#

under Look()

#

yea that why i warned not to just copy and paste, each one of those is a property field u have to create

#

you have to understand what each one is

#

it tells you the type when u hover over it

#

its a simple float, to determine its size

#

thats fine

#

but make it serializedfield and private

#

no need for get and set

visual arch
#

thats a property.

covert marsh
#

[SerializedField] avoid making it public to set in inspector

#

also add this in the code somewhere ```cs
private void OnDrawGizmosSelected()
{
Color transparentGreen = new Color(0.0f, 1.0f, 0.0f, 0.35f);
Color transparentRed = new Color(1.0f, 0.0f, 0.0f, 0.35f);

        if (Grounded) Gizmos.color = transparentGreen;
        else Gizmos.color = transparentRed;
        
        // when selected, draw a gizmo in the position of, and matching radius of, the grounded collider
        Gizmos.DrawSphere(new Vector3(transform.position.x, transform.position.y - GroundedOffset, transform.position.z), GroundedRadius);
    }```
#

helps you debug your ground check

#

u dont need float

#

you need to see where it is so yeah u need it

#

and how big

#

it will turn green if its working

#

then just make a LayerMask where you will add your ground

#

so whats error say now

#

there are literally 3 fields to worry about..

#

not that hard

visual arch
#

add layers inside your unity for GroundLayers

covert marsh
#

groundLayers is a LayerMask type

#

instead of tags, you are using layers

#

so its not "ground" as a tag anymore like u had before but a its a Layer , like above shown by Cat

#

the layer is whatever the ground will be in

#

so you AddLayer call it "Ground"

#

you can add floor to ground to be extra precise, but you can just add Default layer by itself in LayerMask and it will work

#

it's not necessary in the beginning

#

groundoffset is a vector 3

#

groundlayers is LayerMask

#

groundedOffset is a float

#

its very simple code, it just makes a sphere under ur feet..the offset u have to fix so it matches the inside of player collider

#

bcuz u need to add the bool now

visual arch
covert marsh
#

Grounded =

covert marsh
#

i did even say it, it returns a bool lol

#

private bool Grounded;

#

no =

#

it's already declared as a physics ball

#

so if its grounded, u jump

visual arch
# visual arch Remmeber this code?

it will tell you whather you were in Layers Ground or Not, so False you cant jump and true you can jump, that's why debug it's important

covert marsh
#

did you add gizmos and u turn them on? can u show the scene now?

#

nope

#

should have something like this

visual arch
#

Click on the player double click it

covert marsh
#

then come back and do it, im not rushing anything

#

im already spoon feeding you as it is

#

so far i have nothing but helped lol

#

you just gotta pay more attention

#

try harder

#

did you add gizmos line right?

#

after enable this..

visual arch
#

Don't forget to click this.

covert marsh
#

click ur player, and show the sphere

#

u should see it

#

post the new code

#

dude show inspector values

#

did u set the radius size?

#

...

#

bruh see what i said pay attention

#

if its 0 how is a sphere with 0 redius show up ?

#

com on

#

thats why i said start moving it and u see it in sceneview

#

match the bottom of the capsule collider of player

visual arch
#

whatever you want you can adjust it later.

covert marsh
#

no

#

use ur own brain and put in a value

#

see

#

its simple

visual arch
#

yep number

covert marsh
#

also LayerMask and groundedoffset are serializefields

#

u have to set those in inspector too

#

i said that 100 times already

visual arch
#

Like i said before this thread, it's your games you can do whatever you want to the player make your own rule.

covert marsh
#

oh lord

#

why u not pay attention

#

i said groundedoffset was didnt i?

#

thats what you should get

visual arch
#

here's how to fix this instead asking someone, can you please hove the mouse into the swiggle red line?

#

VS will tell you what's wrong with that

covert marsh
visual arch
covert marsh
#

its literally right there

#

just fix it

#

dont leave a project with broken errors

#

meh who needs sleep

#

ehh guess im confusing , sorry

#

you're literally 2 variable away from fix

#

Im always on, u can hit the thread anytime if u left to not autodelete