- Home /
Fall Damage Script Problem?
Hello! So i have my first person controller up in the air on a cube in order to test this kind of Fall Damage script. You know as soon as the player hits the ground i want to see the message "Take Damage!" in the console. The issue here is that as soon as i hit play i get spammed by this message even when i am up on the cube. This is the script i use:
function Update(){
var up = transform.TransformDirection(Vector3.up);
if(Physics.Raycast(transform.position, -up, 10)){
Debug.Log("Take Damage!");
}
}
Of course later i'll make it so that the player has some actual healt but for now let's do the actual fall damage thingy :P
Answer by MrSteve1 · Apr 19, 2013 at 01:20 PM
For that I wouldn't bother with Raycasting, I would use :
function OnCollisionEnter(hit : Collision)
{
if(hit.gameObject.tag == ("Floor")
Debug.Log("Take Damage");
}
This will do it each timer you hit any object you tag "Floor"
Thanks! Theoretically, that should work. However, i just used it and i don't see any message from the console :( Is it because i use a Plane tagged "Floor" as my floor? But even planes are considered gameobjects right?
Also, wouldn't that be confusing a bit later on? Simply because the player won't be up in the air all the time and will have to walk on the floor too. I'm pretty new to Unity3D so please excuse those stupid questions of $$anonymous$$e :P