#[Help] Unity CharacterController - Push Velocity works different in build than in-editor.

13 messages · Page 1 of 1 (latest)

storm lantern
#

Hi everyone. Thanks for the help.


I'm using Unity 6.3 LTE. I have a CharacterController attached to a player, and am adding various desired Vector3's to the player based on desired movement.
I'm trying to overcome the problem where the player can approach an edge and begin 'walking off', and stick to the walls.
https://www.youtube.com/watch?v=Flral1NhFUo

Current Solution:
1.) Using Physics.SphereCast, I cast straight down for collision. With the _hit.point, I get the degree of the slope.
2.) If the degree isn't 0, I run a second Physics.RayCast straight down. If there's no ground within range, the player isn't on a slanted surface and must be hanging off a ledge, so I continue.
3.) If that degree when hanging off a ledge is greater to 10 degrees, I begin finding the angle to slowly push the player off the ledge. The percentage uses linear formula between 10 degrees (0%) to 80 degrees (100%), multiplying that against the maximum force (2 units up to 10 units), and the vector away from the ground (thus pushing them over the ledge).
https://codeshare.io/5OXoKj

As usual, everything works exactly as desired in the editor. As shown in the video, the bare minimum Velocity.Magnitude starts at 2 units per frame, increasing to 10 units per frame. For the editor part of the video, the moment the player reaches the ledge, I do not touch the keyboard anymore and the player slowly pushes off.
Immediately after, I build the game (to show no discrepancies) and perform the same exact action. As you see, the player doesn't exactly 'stick' to the wall, but doesn't have enough force applied to be pushed over the ledge.

#

Further information: When printing out the actual PushVector.Magnitude, the values are as follows:

In Editor: 0.006957611 (2 units) up to 0.06816695 (10 units).
Built Game: 0.001984XXX (2 units) up to 0.01007505 (10 units).

The following are the CharacterController settings, the Physics2D settings (which I don't use directly unless the CharacterController uses them, but other Google searches stated to change the Simulation Mode), and Collision Settings, just for information.


Does anyone happen to have any insight or knowledge of what might be going on? I've been spinning on this for a week and have no idea what to do anymore.

hollow sigil
#

Are you calling that function in FixedUpdate or Update ? Physics run in FixedUpdate so if you call physics queries in the Update the results will be different because Update is frame-rate dependent.

Also not sure why you changed the Physics2D to Update, are you doing 2d stuff as well? I only saw 3d physics in the video you posted.

storm lantern
#

Thanks for the response!!

Update, not FixedUpdate. I was at a point where I was throwing stuff at the wall to see what stuck.

I changed the setting in Physics2D because... Well, that's what the other search result suggested. Honestly didn't even think to check Physics. 🤦🏻

I didn't put much stock into Physics in the first place since I'm not using any rigidbodies, only the collider within the official CharacterController asset. I plan to check Physics and make that change as soon as I can, and see if that hopefully fixes it.

hollow sigil
#

Btw rule of thumb, if it does physics queries it goes in the FixedUpdate. If it's everyhting else like input reading, logs, system interaction it goes in Update.

storm lantern
#

Thanks 🙂 Yeah, that's one thing I've known for many, many years. This was just my first time using the official CharacterController, as in the past I've tried writing my own player controllers through the RigidBody and FixedUpdate.

storm lantern
hollow sigil
#

If I understand correctly you moved all your logic to Update and set the sim to run on Update in the project settings? If you change your physics to run at update that makes it unpredictable. It will be frame-rate dependent. If you need realistic physic sims you need to run it at a fixed rate so that the physics systems can run multiple times / frame.

storm lantern
#

Are velocities applied upon the CharacterController's .Move() function considered physics? Up until now, I was under the belief it was not considered a Physics or RigidBody-like use.

#

All player logic have always been under Update and was never moved to FixedUpdate.

#

I'm trying out changing Simulation Mode to 'Script' to see what changes there.

#

Bah. No joy. Gah, I really hate how inconsistent this is.

storm lantern