Hello guys,
Here’s the case: I’ve made a tiltboard game where you control the tilt of the board and you have to balance a ball on a course and not make it fall of. The ball uses only standard components such as gravity and constant force in order to move, thus reacting physically to the boards tilt. If it falls of and onto the floor I’ve made a panel with a respawn script as follows:
using UnityEngine;
using System.Collections;
public class PlayerRespawn : MonoBehaviour
{
//A reference to the game manager
public GameManager gameManager;
// Triggers when the player enters the water
void OnTriggerEnter(Collider other)
{
// Moves the player to the spawn point
gameManager.PositionPlayer();
}
}
The respawn scripts points to a gamemanager script that you can find here (sorry for the long script):
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class GameManager : MonoBehaviour
{
// Place holders to allow connecting to other objects
public Transform spawnPoint;
public GameObject player;
// Flags that control the state of the game
private float elapsedTime = 0;
private bool isRunning = false;
private bool isFinished = false;
// So that we can access the player's controller from this script
private FirstPersonController fpsController;
// Use this for initialization
void Start ()
{
// Finds the First Person Controller script on the Player
fpsController = player.GetComponent<FirstPersonController> ();
// Disables controls at the start.
fpsController.enabled = false;
}
//This resets to game back to the way it started
private void StartGame()
{
elapsedTime = 0;
isRunning = true;
isFinished = false;
// Move the player to the spawn point, and allow it to move.
PositionPlayer();
fpsController.enabled = true;
}
// Update is called once per frame
void Update ()
{
// Add time to the clock if the game is running
if (isRunning)
{
elapsedTime = elapsedTime + Time.deltaTime;
}
}
//Runs when the player needs to be positioned back at the spawn point
public void PositionPlayer()
{
//player.GetComponent<Rigidbody>().velocity = Vector3.zero;
player.transform.position = spawnPoint.position;
player.transform.rotation = spawnPoint.rotation;
}
// Runs when the player enters the finish zone
public void FinishedGame()
{
isRunning = false;
isFinished = true;
fpsController.enabled = false;
}
The problem is that the ball conserves it’s speed on respawn and I need it to be still when it respawns.
The sphere has a tag of “player” and the game object itself is named “Player_Sphere”. Any help from this awesome community? Thanks in advance!