I currently have a side scroller where an enemy follows a player within a certain distance and i need a way for the enemy to know when the jump. I had an idea of placing a cube with an empty mesh and putting it wherever i need him to be able to jump but the issue is that since theres a collider on the invisible cube he hits it and then jumps over it… also the player can land on it and seemingly float in the air because theres a collider on it. Heres my code that tells the enemy to jump.
using UnityEngine;
using System.Collections;
public class jumpdetect : MonoBehaviour {
private bool isjumping = false;
void OnCollisionStay(Collision theCollision){
foreach (ContactPoint contact in theCollision.contacts) {
if(contact.normal.y > 0.9f){
isjumping = false;
break;
}
}
if(theCollision.gameObject.tag == "jump" & isjumping == false){
rigidbody.velocity = new Vector3(rigidbody.velocity.x, 5, 0);
isjumping = true;
}
}
}
I want to be able to have the object invisible and seemingly nonexistant but i cant remove the collider and still utilize the oncollisionstay function. Any ideas?
Thank you very much!
– asfdasc