FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionfps tutorial

more_horiz
In MisterNinjas fps tutorial he shows how to get the player to damage and all but I can't figure out how to make the enemy do damage to the player

descriptionRe: fps tutorial

more_horiz
You need to recreate the EnemyHealth and make it for the Player and then apply similar damage from scripts the player uses.. i added a p to see differences in code..
IE

Code:

#pragma strict

var Health = 100;

function ApplyDammage (TheDammage : int)
{
   Health -= TheDammage;
   
   if(Health <= 0)
   {
      Dead();
   }
}

function Dead()
{
   Destroy (gameObject);
}

becomes

Code:

NAMED PlayerHealth

var pHealth = 100;

function pApplyDamage (pTheDammage : int)
{
   pHealth -= pTheDammage;
   
   if(pHealth <= 0)
   {
      pDead();
   }
}

function pDead()
{
   Destroy (gameObject);
}

Give the enemy a Damage like you did for the player bullet shooting..

Code:

var pDamage = 100;

function OnCollisionEnter (info : Collision)
{
   info.transform.SendMessage("pApplyDamage", pDamage, SendMessageOptions.DontRequireReceiver);
}


hope this pushes you to right direction.. I would could should write it to teach you but im not a fan of JS as for uni standards and C# is been the push by ALL the company's iv spoken to offering JOBS...

descriptionRe: fps tutorial

more_horiz
you could also give your Enemy a Gun if its an FPS, and have them raycast to you. and get the hit infomation.


e.g (C# Example)

Code:


public int Damage = 10;
RaycastHit hit;

 Ray ray;
           

            if (Physics.Raycast(transform.position, Vector3.forward, out hit, 250f))
            {
                Debug.DrawLine(transform.position, hit.point, Color.red, 2f);

            if(hit.collider.tag == "Player")
                hit.collider.GetComponenet<HealthScript>().Health -= Damage;
            }



Just make sure that the HealthScript is the script that has the Health you want to minus on your player.

_________________
https://www.youtube.com/channel/UCrS-nC8CYukMmhAKpyq6TCA
Permissions in this forum:
You cannot reply to topics in this forum