Question by
SquareEyesTaco · Oct 26, 2015 at 02:56 AM ·
enemydamage
enemy death physics
SO i have my enemys walking around the level. they have a rigid body and a collider. Im going to do it so when he collides with my character during his attack animation he gets knocked away and gradually phases away like the enemys in banjo kazooie.
what i want to know is when i have the oncollide expression how do i make the enemy roll away and fade? how do i tell unity to do the physics of that?
This is the basic script i have for my enemy to wander around.
public class Wanderingai : MonoBehaviour {
public float speed = 3.0f;
public float obstacleRange = 5.0f;
[SerializeField] private GameObject fireballPrefab;
private GameObject _fireball;
private bool _alive;
void Start() {
_alive = true;
}
void Update() {
if (_alive) {
transform.Translate(0, 0, speed * Time.deltaTime);
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
if (Physics.SphereCast(ray, 0.75f, out hit)) {
GameObject hitObject = hit.transform.gameObject;
if (hitObject.GetComponent<PlayerCharacter>()){
if (_fireball == null){
_fireball = Instantiate(fireballPrefab) as GameObject;
_fireball.transform.position =
transform.TransformPoint(Vector3.forward * 1.5f);
_fireball.transform.rotation = transform.rotation;
}
}
else if (hit.distance < obstacleRange) {
float angle = Random.Range(-110, 110);
transform.Rotate(0, angle, 0);
}
}
}
} public void SetAlive(bool alive) { _alive = alive; } }
Comment
Your answer
Follow this Question
Related Questions
duplicating enemies not working correctly 1 Answer
Damage is done to enemy even when not attacking 0 Answers
seek a player 0 Answers
Check between two colliders on one object 0 Answers
why does my enemy attack backwards? 0 Answers