#If it’s long you should create a thread
1 messages · Page 1 of 1 (latest)
Creating a thread just in case
this is all the relevant code and the issues I'm stumbling accross
this too I suppose
you can get the idea of what I'm doing. For some reason, the "grounded" raycast check is just not working no matter what value I set it to. It's incredibly janky and usually just works on a single slope (no matter what value I set.) whatIsGround is set to the correct objects
Even if I remove the "grounded" check in the conditions for a jump, it still doesn't allow you to do it consistently
The movement of the player sometimes just stops briefly too as of the addition of gravity? It's hard to explain
and lastly, the player gets stuck on objects sometimes, which is probably a whole separate issue I have to resolve
Oof this is a lot. Let’s keep it simple first. What’s the issue?
For context: I'm trying to switch my character movement script from using character controller to using a rigidbody, as I've been recommended to make the switch to have an easier time down the line and generally better movement. But honestly, so far it's been pretty dreadful
Just 1 thing to focus on for now
Is it the raycast?
The #1 issue to resolve rn is the grounded check with the raycast
gotcha
a lot hinges on it and it's performing poorly
I've been following this video very closely https://www.youtube.com/watch?v=f473C43s8nE
FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial
In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.
If this tutorial has helped you in any way, I would really appreciate...
set up a lot of things in my code and scene as closely as I could to match it
as for the gravity, I touched it up a bit in fear that constantly applying a force downwards would screw up horizontal movement (x and z), so I opted to only have gravity start applying a downwards force (that gets accelerated) if the grounded check is false
The raycast seems correct… Is it working on flat surfaces?
nope
and you set the layermask correctly right?
yes
triple checked
I even tried it when removing the layer check, same results
honestly deliberating scrapping all this and returning to character controller... (although thats gonna bring its own set of problems back)
add this so the raycast is visualized
void Update()
{
Debug.DrawRay(transform.position, Vector3.down * 1.1f, Color.red);
}```
Do you see a line being drawn from the player to the ground?
hmm weird
wait what was that about gizmos
Make sure you have gizmos drawing turned on in order to see the line
But that was to game view and you were looking at scene view
Is the game running?
Okay let’s try this
void Update()
{
Debug.Log($"Raycasting from {transform.position} to {transform.position + Vector3.down * 1.1}");
}```
See if the numbers it generates make sense
you can spawn a gameobject on those coordinates to see if it intersects the ground. If it does then show the inspector of the ground
honestly idk what to make of this, it's useful info tho
Create a cube at that first Vector3
is it the same position as the player?
sure
approximately
alright show the layermask of the raycast and the inspector of the ground
ugh this looks correct. Im out of ideas
you and me both
I've consistently had trouble with casts working of all types
they just dont wanna work for some reason, or they work half the time
Im literally on the ground why dont you work
Your script is disabled
when the game is paused
when I unpause it reenables itself
anyways yeah, the second I get on a slope it registers
otherwise it doesnt even if I put the value at 9999
This right?
Is the raycast under the ground?
hold on thats a good question
okay well
I tried "transform.position + Vector3.up" instead of just "transform.position"
no difference
oh wait mb
I did it on the debug raycast lol
YEP THAT WAS IT
thank you
🎉
do you think I overcomplicated the hell out of it here
Definitely. Gravity should be constant, some people do make it so it’s slightly weaker when jumping upwards and set it to something stronger when the player is falling but it’s pretty uncommon to have something like “gravity acceleration” since gravity is already an acceleration force
hmm, I found that for some reason when I was applying downwards force it always seemed to move the ridigbody at a constant instead of accelerating it
We can keep it simple first:
void FixedUpdate()
{
rb.AddForce(Vector3.down * someValue, ForceMode.Acceleration);
}```
Try this for gravity
by default unity should have gravity set to 9.81f
oooooooooh
if it was too floaty, you would up that value to something higher
It’s the same thing but doesn’t account for mass
strange
^ Try this first without your custom gravity implementation. If you want a different effect lemme know
alright thank you a lot
that's a lot smoother
and the random jankiness seems to have gone away
do you perhaps know of a good way to make the player not "freeze" when running into a wall?
freeze?
yeah, as in, when colliding with a wall sideways, as long as the player is holding down the button which makes the capsule collide with the surface, it freezes in place, being unaffected by any force including gravity
you mean like stick to walls
gotcha
you can add a frictionless physics material to the wall
is there a way for it to apply universally?
I don’t believe so
I have quite a lot of walls and intend on having a lot more
would be quite annoying having to do that for each and every one
actually I think i see something
You can add a collider to the player, that’s slightly wider but shorter
and add that physics material onto that collider
yeah something like that is what I'm looking for
how would I ensure that physics material doesn't serve as a bullet vest or the player capsule collider and it don't clip?
you could set it as a separate layer that bullets can’t collide with
and how do I ensure the capsule and it don't collide?
As long as that collider is a child of the player it’s fine I believe 🤔
could I make it a child of the capsule?
Otherwise if not, you can set the player to a layer that doesn’t collide with the “slippery vest”as well
Yes
alright, and now I just create a sliperry material?
You’d set both frictions to 0
did I do it right?
seems so
it doesnt seem to be working
make sure it’s slightly wider than the player
scale is 1.02 0.88 0
radius
adjusted the radius, still isn't working
radius is 0.6 now
does it need a rigidbody?
The player has the rigidbody right?
The vest should be a child of the player
hmm i guess so then
maybe provides contacts?
The physics material should be 0, 0, 0 minimum minimum
thank you so much for the help man