- Home /
Speed Different In Exe Than Game Window
Title Says The Problem, I'm Not Sure Where To Put Time.deltaTime either
void Start()
{
forceZ = 15;
}
void Update()
{
// Forward Movement
if (fallen == false) {
cameraFollow.position = ballTran.position;
}
ballRg.AddForce(forceX, forceY, forceZ);
// Forward Movement End
// Sideways Movement
if (Input.GetKeyDown("a")){
forceX = -10;
}
else if (Input.GetKeyUp("a") && !Input.GetKey("a") && !Input.GetKey("d")) {
forceX = 0;
}
if (Input.GetKeyDown("d")) {
forceX = 10;
}
else if (Input.GetKeyUp("d") && !Input.GetKey("d") && !Input.GetKey("a")) {
forceX = 0;
}
if (Input.GetKeyDown("a") && Input.GetKeyDown("d")) {
forceX = 0;
}
// Sideways Movement End
// Deaths
// Falling Death
if (ballTran.position.y <= -35) {
fallen = true;
}
}
}
Answer by frederikedel · Dec 11, 2020 at 01:03 PM
The problem lies in the fps difference form different devices or systems (unity, build). In this case its faster, becaus it runs standalone. First, always do movment in FixedUpdate, it is much better for physics and stuff. And to fix the problem, just multiply the force by Time.DeltaTime like you already wrote.
First, always do movment in FixedUpdate, it is much better for physics and stuff
False. $$anonymous$$oving a Transform in Update
is totally fine as long as you don't want to detect collisions. $$anonymous$$oving an object relying on physics should be done in FixedUpdate.
And to fix the problem, just multiply the force by Time.DeltaTime
False, especially if you call AddForce in FixedUpdate. The time between two calls of FixedUpdate is not Time.deltaTime
, and even if it were, you don't want to involve time when applying a force. A very simple example proving you should not apply Time.deltaTime (not even Time.fixedDeltaTime) is to have two cubes. One with gravity enabled, the other without gravity enabled but the following script:
private void FixedUpdate()
{
GetComponent<Rigidbody>().AddForce(Physics.gravity);
}
The two cubes will fall at the same speed.
Your answer
Follow this Question
Related Questions
Problem with flickering screen when changing resolution 0 Answers
Unity 5.1.3f1 won't open 0 Answers
Keep getting error, it's making me mad. 1 Answer
tornado twins worm game tutorial turret not firing 2 Answers