#i used the jump script in the video and it doesnt work

1 messages ยท Page 1 of 1 (latest)

knotty canyon
#

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...

โ–ถ Play video
river knot
#

Have you checked if the grounded variable is working properly? Maybe the object the player is standing on is not in the same layer as defined in the ground layermask

knotty canyon
#

as you mean?

#

the ground is layered whatisground

river knot
#

and the layer mask variable in the script is also whatisground?

river knot
#

ok, have you checked the readyToJump and grounded fields in the inspector in debug mode?

knotty canyon
#

or at least the readyToJump

river knot
# knotty canyon i think so ya

maybe try adding a debug.log right before you call jump and before the if statement to see if it gets called, like Debug.Log("Test1") before the if and Debug.Log("Test2"), if you see just the first log you know it's one of them

#

you can also set the inspector to debug mode by clicking on the three dots right next to the lock and when you select the player object you should see the variable fields

knotty canyon
#

like this?

river knot
#

yeah should work, now if you press space and see only the 'helloworld' you know the booleans are set to false

knotty canyon
#

i didnt even show

#

debug log 1 and 2

river knot
#

ok, means either grounded or ready to jump is false, is readyToJump getting set to true from other scripts or is it just this script?

knotty canyon
river knot
#

ok then i guess you found the iussue readyToJump is never getting set to true so the reset jump call will never get executed and stays false meaning the player can't jump, so just add a line in the start function like readyToJump = true;

knotty canyon
river knot
# knotty canyon

Can you show me an image of the inspector of the player script?

knotty canyon
#

normal

river knot
#

I mean like from the unity object in the editor with the script attached to it

knotty canyon
#

oh lol

#

my fault

river knot
#

ok... try running the game with the inspector open like this and look how 'grounded' changes

knotty canyon
#

it doesnt change

river knot
# knotty canyon

alright, means the only thing left that could fail is this line:
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround);
Are you 100% sure the plane on which the player is standing is in the layer 'what is ground'?

vernal geode
#

Can you make sure that your ground objects are layered with isground?

#

I didnt see it in the video but I just may have missed it

#

Also your player is layered as whatisground, which means your jump raycasts can hit your player

#

which doesnt seem correct to me

knotty canyon
knotty canyon
#

lol

vernal geode
#

Shouldnt make a difference as long as it has collision :P

river knot
#

yea maybe try changing the player layer to default instead of whatisground

vernal geode
#

wait I think I see it

#

the math for your raycast looks off

knotty canyon
#

?

vernal geode
#

1 sec let me verify this

knotty canyon
#

ok

river knot
#

if the main player object is directly on the ground
grounded = Physics.Raycast(transform.position + Vector3.up, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround);
should help

knotty canyon
#

ok well lets try this a get

vernal geode
#

I have a feeling it could be where the actual cast is, so lets check. You can draw the ray with

Debug.DrawRay(transform.position, Vector3.down * playerHeight * 0.5f + 0.2f, Color.green);
#

When in game, switch to the scene view after putting this alongside your raycast call. You will be able to see the cast lines

#

If you cant find them anywhere or they're in the wrong spot its a math problem, if not we can circle back to the physics/layers ๐Ÿ˜„

knotty canyon
#

errors

river knot
#

just change it to
Debug.DrawRay(transform.position, Vector3.down * (playerHeight * 0.5f + 0.2f), Color.green);

vernal geode
#

^^

vernal geode
#

Oh maybe your code is moving the player mesh subobject but not the parent transform

#

Let me check code

#

that or there is a large offset

knotty canyon
vernal geode
#

I dont think they should be necessary for now, but if you want to send them for goodmeasure so we can check that is fine

knotty canyon
river knot
#

Or can you like provide a download for the unity scene from your project files?

vernal geode
#

Yeah I think that would make this a lot easier

knotty canyon
#

how do i do that?

vernal geode
#

You can take your project file and turn it into a .zip, or another archive format

#

If you have winrar its very easy

#

If not im not sure, intfloat might know

#

ive always used winrar

knotty canyon
#

ok

#

i will send a media fire link

river knot
#

perfect

knotty canyon
#

and i will make a zip

#

you guys sewe anything?

river knot
#

almost... I think the first step would be changing the layer of the 'Player' object to default and the layer of the giant cube to 'whatIsGround'
and then go through every child of the player object (playerObj, cameraPos and orientation) and set their position to 0, 0, 0

knotty canyon
#

ok

river knot
#

YES finally, set the player height to sth like 5 and the jump force to like 10 and it should work!

river knot
#

ok wait a minute... let me just record what i did

knotty canyon
#

ok'

river knot
knotty canyon
#

i love all of you thank you

river knot
#

glad to hear that! had a lot fun finding that problem!๐Ÿ‘

knotty canyon
#

ok thx a lot

river knot
#

for any futher question feel free to ask them!

knotty canyon
#

ok