- Home /
Question by
angryFlo · Aug 15, 2014 at 08:36 AM ·
rotationpositionwaypoint system
Problem with waypoints and positon+rotation changing
Hi, i try to use waypoints to let a car drive through a array of waypoints, if the car hit a special object it should then use the waypoints to drive a specific way.
But my problem is the car drives through mysterious coordinates i can't understand.
Maybe someone can explain me what i'm doing wrong her ?
This is the script attached at the car:
using UnityEngine;
using System.Collections;
public class CarLogic : MonoBehaviour {
public float maxSpeed = 5f;
public float currentSpeed;
Transform[] PathLeft;
Vector3 nextposition;
Quaternion nextrotation;
void Start() {
Go();
}
void FixedUpdate() {
rigidbody.MovePosition( rigidbody.position + (transform.right * currentSpeed * Time.fixedDeltaTime) );
}
void Go() {
currentSpeed = maxSpeed;
}
void Left() {
currentSpeed = maxSpeed;
for ( int i = 0; i < PathLeft.Length ; i++)
{
nextrotation = PathLeft[i].rotation;
nextposition = PathLeft[i].position;
}
transform.rotation = Quaternion.Slerp(transform.rotation , nextrotation , Time.fixedDeltaTime);
}
void Stop() {
currentSpeed = 0f;
}
void OnTriggerEnter(Collider other) {
Transform trans = other.gameObject.transform;
if ( trans.CompareTag("Ampelstreifen") || trans.CompareTag("Auto") ) {
Stop();
}
}
void OnTriggerExit(Collider other) {
Transform trans = other.gameObject.transform;
if ( trans.CompareTag("Auto") ) {
StartCoroutine(PauseAndGo());
}
}
void OnTriggerStay(Collider other)
{
Transform trans = other.gameObject.transform;
if ( trans.CompareTag("Ampelstreifen") ) {
if ( trans.GetComponentInParent<AmpelLogic>().state ) {
PathLeft = trans.Find("PathLeft").GetComponentInParent<WayPoints>().wegpunkte; //Get the Waypoints from another script
Left();
}
}
}
IEnumerator PauseAndGo() {
yield return new WaitForSeconds(pauseBeforeGo);
Go();
}
}
Comment
Your answer