Zina
Zina

Reputation: 159

Trouble with RigidBody

I am making a fps in unity and a game mechanic that I am trying to get is wall running/jumping I have watched many tutorials but they cant fix the trouble I am having. To understand the code I need to explain the wall run. Basically what happens is that I have an empty game objectenter image description here

that raycast the left and the right of the player detecting for a wall. if it finds a wall and I'm holding left or right button (depending on what side the wall is on) it will add a force pushing the player towards the wall and another force pushing me forward. if I jump of the wall it will add a force depending on where I jumped. to make sure it was working I made a bool Value called iswallrunning but its never been set to true. can I get help with this

Code: https://github.com/ZeeScratcher/Project-robot-game/blob/main/WALLRUN.cs

Upvotes: 1

Views: 58

Answers (1)

beuzel
beuzel

Reputation: 74

Looking from the code:

you should only write code into the methods which they are responsible for. In StartWR() do not call StopWR(). This will be done in CheckForWR().

I don't know where Orientation comes from. I suppose this is from a child game object. This is fine, for a test replace Orientation by transform.

You can visualize the rays with Debug.DrawLine().

Better apply the physical force from the event FixedUpdate() instead of Update().

It is safer and more performant to cache with GetComponent() in the Awake or Start method instead of Update. If you are next to a wall in the first frame you will get a null pointer error otherwise.

Check if your walls match your given physical LayerMask and the walls have colliders.

If it is easier for you write all code into the Update() method and split it later into methods.

It would be nice to upvote my message, so I can finally make comments in Stackoverflow.

Kind Regards, Chris

Upvotes: 1

Related Questions