Welcome!

Welcome to our community forums, full of great people, ideas and excitement. Please register if you would like to take part.

This is extra text with a test link..

Register Now

Announcement

Collapse
No announcement yet.

AIAttackScript For Melee Attacks and Ranged Attacks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • AIAttackScript For Melee Attacks and Ranged Attacks

    Code:
    import AIBehavior;
     
    class AIAttackScript extends MonoBehaviour
    {
       var launchPoint : Transform;
       var projectilePrefab : Rigidbody;
       var projectileSpeed : float;
       
       var sphereCenter : Transform;
    	var sphereRadius : float;
       
       function MeleeAttack ( attackData : AttackData  ) : void
       {
    	Debug.Log("Melee attack");
    	var hitColliders = Physics.OverlapSphere(sphereCenter.position, sphereRadius);
    
    	for (var i = 0; i < hitColliders.Length; i++) {
    		Debug.Log("I'm overlapSphering and an object in my sphere is " + hitColliders[i].collider.gameObject.name);
    		if (hitColliders[i].collider.gameObject.tag == "Player"){
    			hitColliders[i].collider.gameObject.GetComponent(Health).ApplyDamage(20);
    		}
    	}
       }
    
       function RangedAttack ( attackData : AttackData  ) : void
      	{
    		var projectile : Rigidbody;
    		projectile = Instantiate(projectilePrefab, launchPoint.position, launchPoint.rotation);
    		launchPoint.transform.LookAt(GameObject.Find("First Person Controller").transform);
    		
    		projectile.velocity = launchPoint.transform.TransformDirection (Vector3.forward * projectileSpeed);
    	}
    }
    We welcome the arrival of a Phantom at Sunset, only to rue its departure at sunrise. What is it?
    You had a bad day once, am I right? I know I am. I can tell. You had a bad day and everything changed. Why else would you dress up as a flying rat?
Working...
X