Hertzole / gold-player

A first person player controller for Unity.
MIT License
160 stars 16 forks source link

Bug? #23

Closed mwg3 closed 5 years ago

mwg3 commented 5 years ago

Hi, thanks for really good movement script. But i have two problems When my player want to jump he hits the roof? and when im trying crouch he's under the world... Could you help me? Thanks a lot!

Hertzole commented 5 years ago

Hello! I'm not interely sure what you mean. Do you think you could send me a project where you can reproduce this or record the problem? That way I can get a much easier understanding of what's going on. :)

mwg3 commented 5 years ago

Project is really big cause he has a lot of objects. Ok i will try to explain my problem. When i press jump button my player doesn't want to jump? This looks like it's blocking in invisible wall. Really weird.

Hertzole commented 5 years ago

I can think of two possible reasons.

  1. The ground layer on the player (Movement - Other - Ground Layer) is not set up properly. Make sure to put the player on it's own layer and then NOT include that layer in the Ground Layer.
  2. The character controller height and center don't match. The character controller Y center must half of the character controller height. So for example, if the height is 2, the Y center needs to be 1. If the height is 1.8, the Y center needs to be 0.9. This is due to how the ground check and crouch checking work.

Let me know if this fixes your problem! If not, I would really like to see a screenshot of your player inspector so I can see if there are any anomalies. :)

mwg3 commented 5 years ago

Only the first jump works well

Hertzole commented 5 years ago

As I said, a screenshot of your inspector (with the movement tab selected) or a video of the problem would be greatly appreciated! It helps me a lot to see what the problem could be. :)

mwg3 commented 5 years ago

Sure. https://imgur.com/Hsjoapo https://imgur.com/BAXglps https://imgur.com/aEL7Ysk

mwg3 commented 5 years ago

And player layer https://imgur.com/XrO6Y2O

mwg3 commented 5 years ago

Others settings are default

Hertzole commented 5 years ago

In the first picture, I suspect that is the Ground Layer. You need to put every layer there you want to collide with EXCEPT for the player layer. So if your world is generally built up by objects with the Default, Floor, HitBox, etc layer, make sure to add those in the Ground Layer. But exclude the Character layer from that. I hope that helps! :)

Hertzole commented 5 years ago

I also discovered a bug with the crouching (see #24) that might be related to your problem with the player being in the ground when crouching. I'll make sure to fix that ASAP and then I can help you patch it until the next release, which will take a while!

Hertzole commented 5 years ago

Sorry for the semi spam. Just wanted to let you know how to quickly patch the player controller in case you have problem with the crouching.

  1. Open the PlayerMovement script (Hertzole/Gold Player/Scripts/Core/Modules/PlayerMovement)
  2. Change line 256 from m_CrouchCameraPosition = PlayerController.Camera.CameraHead.localPosition.y - m_CrouchHeight; to m_CrouchCameraPosition = PlayerController.Camera.CameraHead.localPosition.y - (CharacterController.height - m_CrouchHeight); (Can also be seen here)

I hope things work out for you! If not, just ask away! :)

mwg3 commented 5 years ago

Hi, thanks for help Hertzole! You're so helpful and i will add information about you in my project! My problem was with rigidbody when "Use gravity" function was on. But i have 2 others problem :/ Your script doesn't have a camera collider and that is problem for me :/ And secondly..how to add knockback functions when player got damage?

Hertzole commented 5 years ago

Hello! Gold Player unfortunately does not support rigidbodies, so some funky behaviour could occur with that. Glad you figured that out! :) I'm not sure what you mean with camera collider. Could you elaborate? Currently there's no support for knockback, but I could probably add that in the next release. I will look into it. Meanwhile, you could try to make a seperate script to apply knockback, like the example I found here. I hope that helps! :)

mwg3 commented 5 years ago

Maybe script like 'rb.AddForce(target.transform.forward * Distance, ForceMode.Impulse);' will work with ur player movement script?

Hertzole commented 5 years ago

Right now I doubt it will work. But I'll do my best to add a easy to use knockback system.

mwg3 commented 5 years ago

Hi brother. I have one mistake and one sugestion. Bug with camera collision https://imgur.com/a/Ek2hJIl And will be awesome if you add on this project Falling damage :) Thanks a lot for good project!

Hertzole commented 5 years ago

Hello! For the camera collision problem, you need to change the near clipping planes on your camera, like this. I usually set it to 0.01. By default, it's 0.3, which can cause this issue. For fall damage, that should already be possible to do in your own scripts using Gold Player. Here a brief summary of how you could do it: In your scripts, like a health script, subscribe to the OnLand event in GoldPlayerController.Movement. If you aren't familiar with C# events, Unity has a good tutorial on it here. Then in your land callback, you can check if the fallHeight is more than your threshold and do damage if the fall height is far enough.

I hope that helps! :)

mwg3 commented 5 years ago

Thank you so much! You're the most helpful guy I've ever seen :-)

Hertzole commented 5 years ago

Thank you! I try my best! :D

I will close this issue now as it seems like it's been resolved. If you have anything else you want to bring up, just comment again or open a new issue.

Remember to keep an eye out for new updates that will (hopefully!) include knockback and other fixes! :)