- Home /
damage health script ineffective, no noticable mistakes
im making yet another slenderman indie, and i am trying to make it so that when slenderman comes in contact with the first person controller it kills him and resets the location, esentially restarting the game. i have my stalking script down but my damage system seems to be ineffective. i have looked at it several times. it is such a simple script yet it remains ineffective. my first person controller contains the rigidbody component while my enemy contains a mesh collider.
var health : int = 100;
private var dead : boolean = false;
var enemyDamage : int = -100;
function OnControllerColliderHit(hit : ControllerColliderHit) {
if(hit.gameObject.tag == "BloodBoss")
{
health +=enemyDamage;
}
}
function Update () {
if(health <= 0)
{
dead = true;
}
if(dead == true)
{
transform.position = Vector3(0,0,0);
}
}
Answer by TheDarkVoid · May 12, 2013 at 01:00 AM
your adding more health everytime you get hit. you need to do this instead
if(hit.gameObject.tag == "BloodBoss")
{
health -=enemyDamage;
}
thank you it worked. however my it seems like the first person controller is now ineffective as a result. i cannot move from a stationary position
sorry for being so needy. im still learning! really new to all this, i've been trying to problem solve but it isnt very successful;)
no, there's no errors. i just can't move anymore, it's like it eli$$anonymous$$ated the character control motor. i think it has something to do with the vector3 in the script because im remaining stationary at the exact values that i set it at; the values im supposed to respawn at after encountering the enemy, i cannot move from.
Answer by ricky1996 · May 15, 2013 at 11:54 PM
try adding this script to your players FPS script just after the variables: : private var dead = false;
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag=="BloodBoss")
{
dead = true;
}
and add this to the end of the script: function LateUpdate()
{
if(dead)
{
transform.position = Vector3(0,0,0);
also remember to make a tag called BloodBoss and add it to your slendeman :)
Your answer
Follow this Question
Related Questions
Health Regeneration 2 Answers
Damage/Health problem 2 Answers
Weapon Mesh Damage 1 Answer
How to get Enemy to break wall between it and Player. 1 Answer
Player Health Damage 2 Answers