Hello!
I’m doing something really simple. I’ve done harder scripts than this and yet I’m all out of ideas.
Basically, I’m landing a player from the air onto the runway. First, the player enters the “Landing zone”. Then this script takes over controls and lands the player. Here it is:
using UnityEngine;
using System.Collections;
public class LandThePlayer : MonoBehaviour {
public GameObject PlayerCamera;
public GameObject LandCamera;
public GameObject Player;
public GameObject LandTrigger;
public GameObject StopPosition;
public bool PlayerIsLanding;
public float LandingTime;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if(PlayerIsLanding == true)
{
LandPlayer();
}
}
//I have a trigger detecting when the player enters a zone to start the landing
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
SwitchCameras();
PlayerIsLanding = true;
Debug.Log("Starting to land the player");
}
}
void SwitchCameras()
{
//this part simply turns off the player's camera and turns on a landing camera
//this is totally for looks and doesn't affect anything else
PlayerCamera.gameObject.SetActive(false);
LandCamera.gameObject.SetActive(true);
}
void LandPlayer()
{
//PlayerFromPoint is where the player is starting to land
Vector3 PlayerFromPoint = LandTrigger.transform.position;
//StopPosition is the end of the player's landing
Vector3 PlayerToPoint = StopPosition.transform.position;
//let's move the player
Player.transform.position = Vector3.Lerp(PlayerFromPoint, PlayerToPoint, Time.deltaTime);
//and let's spam the console
Debug.Log("Player is landing");
}
}
Everything should be working, but the player simply bounces around the PlayerFromPoint, not moving any closer to the PlayerToPoint. What could be wrong with this script? Or should I try something else to achieve the same result?
Thanks for your ideas!
P.S. In case you’re wondering how I got some of this code: