0
\$\begingroup\$

I currently have a problem in my custom character controller. I have code that moves a Gameobject's transform.postion.y to simulate gravity and ground is detected using SphereCast. SphereCast is thrown from the middle of the body towards the bottom. And then I have a big cube as my ground.

When I position the character very high above the cube and then press the Play button, the character drops and SphereCast detects a hit (scenario 1). But when I position it still high above the cube but not as high as the first example, the SphereCast doesn't detect a hit (scenario 2). So it only detects a hit when I start it really high. And this only happens on initial run, because I have a jump function and when I do the first scenario (hits ground) and then do a jump, the landing after the jump is detected by SphereCast even though the jump is same height as scenario 2.

So my next step is, adding a breakpoint in SphereCast hit while playing scenario 2 frame by frame. The thing is, when frame by frame, scenario 2 is detected by SphereCast, so I'm at a lost on how to debug this.

Summary:

  • SphereCast hits ground when character is placed really high above ground then hitting Play button (scenario 1)
  • SphereCast doesn't hit ground when character is placed moderately high above ground then hitting Play button (scenario 2)
  • If scenario 2 is done frame-by-frame, SphereCast hits
  • Need ideas on how to debug
\$\endgroup\$
  • \$\begingroup\$ I guess that you execute the sphere cast inside of the Update method when you should be using the FixedUpdate method. If it is in FixedUpdate you might have changed the FixedTimestep value in the Time settings by accident (default is 0.02). \$\endgroup\$ – Bartimaeus Sep 25 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.