My object falls into a vacuum instead of using Lerp

0

I'm doing a runner-style game that is not generated randomly and I'm trying to program the Boss to come on stage and start the final fight. The game consists of an astronaut (player) who always stays on the screen (so, the background and the camera never move, the player moves but is limited with Clamp).

All the obstacles come to the player and he has to avoid them or shoot them until the last one is the Boss. The Boss is at the end of the row and also moves on the Z axis towards the player and stops as soon as he plays a collider that would already be on the screen, so that the Boss does not move further to the left and start the fight .

After it stops I want the Boss to move from top to bottom and bottom to top with Lerp functions. This is the code:

The code looks like this:

public class BossController : MonoBehaviour {

public float speed;
public float health;
public Animator anim;
public Transform startMarker;
public Transform endMarker;

private Rigidbody rb;
private HUDController hud;
private bool startIntro = false;

private float startTime;
private float journeyLength;

void Start () {
    startTime = Time.time;
    journeyLength = Vector3.Distance (startMarker.position, endMarker.position);

    anim = GetComponent<Animator> ();
    rb = GetComponent<Rigidbody> ();
    rb.velocity = transform.forward * -speed;

}

void Update(){

    if (startIntro) {
        rb.velocity = new Vector3(0,0,0);
        Fight ();
    }
}

 void Fight(){

    float distCovered = (Time.time - startTime) * speed;
    float fracJourney = distCovered / journeyLength;

    transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
    transform.position = Vector3.Lerp(endMarker.position, startMarker.position, fracJourney);

}

void OnTriggerEnter(Collider other){
    if (other.gameObject.CompareTag ("bossEntry")) {
        startIntro = true;
        //anim.SetTrigger ("quad"); 
    }
}

}

The structure is an Empty that contains the mesh, the exit point and the end point for the Lerp. Only the Empty (parent) has a Rigidbody (well two) that are trigger.

Help? Thanks!

    
asked by bonishadelnorte 29.10.2018 в 09:58
source

1 answer

0

Try to remove the rigidbody or activate "Is Kinematic" in the rigidbody options, sometimes the rigidbodies will put the oak by moving them in the update using transform.position, to move a rigidbody it is better to use regidbody.addforce ().

    
answered by 13.11.2018 в 15:28