I have a OnCollisionEnter method in my script. When collision happen my gameobject start diving.
But if in the inspector have only one box collider the gameobject not doing anything.
If i have two box collider on the gameobject, start diving but only than if collide twice.
How can i solve this? I need one box collider and i need to start diving the gameobject at the first collide?
I doesn't really understand why it doing this...
here's my script if you need:
public float speed = 0.5f;
public Vector3 startpos;
public Vector3 endpos ;
private float distance = 15f;
private float lerptime = 40f;
private float currentlerptime = 0;
void Start()
{
startpos = transform.position;
endpos = transform.position + Vector3.down * distance;
}
void OnCollisionEnter(Collision collision)
{
currentlerptime += Time.deltaTime;
if (currentlerptime > lerptime) {
currentlerptime = lerptime;
Debug.Log ("hittreu");
}
{
float perc = currentlerptime / lerptime;
transform.position = Vector3.Lerp (startpos, endpos, perc);
}
}
↧