I want to find when the spaceship has landed and when the landing act finished and then to wait 2-3 seconds and then to do something else.
In the script i set the landing bool variable by default to true just for the testing.
using UnityEngine;
using System.Collections;
public class ControlShip : MonoBehaviour {
public int rotationSpeed = 75;
public int movementspeed = 10;
public int thrust = 10;
private bool isPKeyDown = false;
private float acceleration = .0f;
private Vector3 previousPosition = Vector3.zero;
Rigidbody _rigidbody;
private bool landing = true;
// Use this for initialization
void Start () {
_rigidbody = GetComponent<Rigidbody>();
Debug.Log("Acc Speed: " + thrust);
}
// Update is called once per frame
void Update()
{
if (landing == false)
{
var v3 = new Vector3(Input.GetAxis("Vertical"), Input.GetAxis("Horizontal"), 0.0f);
transform.Rotate(v3 * rotationSpeed * Time.deltaTime);
transform.position += transform.forward * Time.deltaTime * movementspeed;
if (Input.GetKey(KeyCode.Z))
transform.Rotate(Vector3.forward * rotationSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.R))
transform.Rotate(Vector3.right * rotationSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.P))
{
isPKeyDown = Input.GetKey(KeyCode.P);
float distance = Vector3.Distance(previousPosition, transform.position);
acceleration = distance / Mathf.Pow(Time.deltaTime, 2);
previousPosition = transform.position;
_rigidbody.AddRelativeForce(0f, 0f, thrust, ForceMode.Acceleration);
}
}
else
{
if (_rigidbody.velocity.sqrMagnitude < .01 && _rigidbody.angularVelocity.sqrMagnitude < .01)//much faster than magnitude
{
Debug.Log("Landed");
}
}
if (Input.GetKey(KeyCode.L))
{
landing = true;
}
}
void OnCollisionEnter(Collision col)
{
if (landing == true && col.gameObject.name == "Base")
{
}
}
void OnGUI()
{
if (isPKeyDown)
{
GUI.Label(new Rect(100, 100, 200, 200), "Acc Speed: " + acceleration);
}
}
}
The spaceship object have a rigidbody component and a box collider component.
Also the Base(Cube in red) have a box collider.
What i want to do is to detect/find when the landing is finished and once the spaceship landed to wait 2-3 seconds and then do something after the 2-3 seconds.
I tried to use this part in the script but it’s not working good it’s showing the Debug “Landing” just when running the game.
I attached a youtube short video clip showing the landing and the base and spaceship objects and inspector of them: