#i used the jump script in the video and it doesnt work
1 messages ยท Page 1 of 1 (latest)
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...
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
and the layer mask variable in the script is also whatisground?
should be
ok, have you checked the readyToJump and grounded fields in the inspector in debug mode?
i think so ya
or at least the readyToJump
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
like this?
yeah should work, now if you press space and see only the 'helloworld' you know the booleans are set to false
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?
just the script
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;
Can you show me an image of the inspector of the player script?
I mean like from the unity object in the editor with the script attached to it
ok... try running the game with the inspector open like this and look how 'grounded' changes
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'?
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
im about 100% wrong it is not a plane
lol
Shouldnt make a difference as long as it has collision :P
yea maybe try changing the player layer to default instead of whatisground
?
1 sec let me verify this
ok
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
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 ๐
just change it to
Debug.DrawRay(transform.position, Vector3.down * (playerHeight * 0.5f + 0.2f), Color.green);
^^
ok
nice it worked
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
do you what the camera scripts
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
Or can you like provide a download for the unity scene from your project files?
Yeah I think that would make this a lot easier
how do i do that?
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
perfect
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
ok
YES finally, set the player height to sth like 5 and the jump force to like 10 and it should work!
sad
ok wait a minute... let me just record what i did
ok'
Is the readyToJump = true still in the start method?
i love all of you thank you
glad to hear that! had a lot fun finding that problem!๐
ok thx a lot
for any futher question feel free to ask them!
ok