#Fixing Some Character Glitches
1 messages · Page 1 of 1 (latest)
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
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;
}
}
so you only have this one.
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
thats a property.
[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
add layers inside your unity for GroundLayers
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
ah now i get it so that's why it's better using Sphere/Raycast system instead doing it with Collision.
Grounded =
Remmeber this code?
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
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
did you add gizmos and u turn them on? can u show the scene now?
nope
should have something like this
Click on the player double click it
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..
Don't forget to click this.
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
whatever you want you can adjust it later.
yep number
also LayerMask and groundedoffset are serializefields
u have to set those in inspector too
i said that 100 times already
Like i said before this thread, it's your games you can do whatever you want to the player make your own rule.
oh lord
why u not pay attention
i said groundedoffset was didnt i?
thats what you should get
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
you can lead mule to river water but you cant force to drink it
im gonna be honest with you, i had no idea what you are talking about. but anyway thank you i found something intresting in this thread by using sphere/raycast system for player instead use Collision