Movement stops after restarting the scene
Hello,
I have a problem with Rigid Body movement. I am trying to create endless runner type of game, where player needs to dodge the blocks infinitely. I am spawning row of blocks in front of the player by instantiating the prefab with the following script attached:
using UnityEngine;
public class BlockMovement : MonoBehaviour {
public Rigidbody rb;
public float backwardForce = 1000f;
void Update () {
rb.AddForce(0, 0, -backwardForce * Time.deltaTime);
}
}
It causes to move them towards player on the surface with slippery (dragless) physics material.
In the beginning everything works fine but as soon as I restart the scene (after hitting the obstacle), they remain stationary and soon after another wave spawns in the same place causing them to explode in all directions.
I am restarting the scene using the following line, triggered after hitting the block:
SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
I was trying to find the solution for this problem everywhere, tweaking the parameters of motion, interval between waves and mass but nothing seems to work.
The game also slows down time, two second before restarting, using timescale.
If anyone encountered similar problem or knows the solution, I would be grateful for help.
Thank you in advance!
Your answer
Follow this Question
Related Questions
rigidbody velocity changes rapidly(fly) after change timescale 1 Answer
Why my gravity direction is rotating with transform.rotation? 1 Answer
How to apply a force at certain point of an object? 0 Answers
[Help] Player stops moving when hitting wall diagonally 0 Answers
What about physics happening far from the (floating) origin ? 0 Answers