mgshel
mgshel

Reputation: 1

Unity colliders are moving as expected in the Editor but not in a Build

When in the game editor the game runs as intended and we can pick-up each object selected and move it from point A to point B. When building the game the game starts as intended but after a few moments, we noticed that the collider triggers for the object we want to be picked up are moving upwards indefinitely. There is an animation attached to the floor which will move the player and objects up when activated but the player has to complete a task for the animation to start.

We noticed this because we have an indicator which shows when the RayCast hovers over the collider to pick up the object, and it moves upwards after start.

This issue occurs on every object intended to be picked up in the scene that the player is currently in.

In editor the colliders don't move and the items can be picked up as intended but the issue came about ONLY when trying to build the game.

Tried: Adding kinematics Removing gravity Removing every animation attached in the scene Changing each part of the objects RigidBody Changing the Awake() on pick-up script Running in developer mode

Upvotes: 0

Views: 454

Answers (1)

John B
John B

Reputation: 20390

Is this an issue where you're not accounting for the framerate? In other words, do you need to incorporate Time.deltaTime in your Update loop somewhere? This feels like that because I'm thinking the frame rates could differ drastically between the unoptimized editor environment, and a full build.

For example, if I'm moving an object 10 units each frame like this:

Update()
{
    // Move to the right
    transform.Position.x += 10;
}

Then that is frame rate dependent. On a device with a low framerate, the object will move slower than on a device with a high frame rate. On a 30 average fps device the object will move 300 units per second. On a 120 fps device the object will move 1,200 units!

That code should look something like this to account for frame rate changes:

Update()
{
    // Move to the right
    transform.Position.x += 10 * Time.deltaTime;
}

You may need to adjust the "10" value because now it's related to how fast the object is moving per second. Each Update will move the object a proportional amount of time for that frame.

(The above implementation probably isn't perfect, and introducing things like networking/multiplayer could require additional changes.)

See the docs for more information about Time.deltaTime

Upvotes: 0

Related Questions