- Home /
First Character and loose hit points
Hi everyone,
I'm new in unity3d and i'm trying to do something to understand.
I did a terrain with mountains and rocks, and I want to move and jump my character (first person) around the world.
So, I want to loose "hit points" (health) when they hit with high velocity.
For example, if I jump and hit a rock or on the ground too distance, I must loose health or die (if the collision is strong!).
I`m use the Standard Prefab First Person Controller, and if I put rigidbody component in it, the controller did´nt work well!
Any suggestions?
tks
Answer by ocularcash · Sep 24, 2011 at 12:37 AM
the first person controller that comes with unity has alot of bugs when you attach a rigidbody. Here's a simple script you can use as a move script. just add this script to whatever you want as a character and go to component/camera-control/mouse look and add it and also go to component/physics/character controller and add it.
public var MoveSpeed : float = 50;
public var jumpSpeed : float = 55;
public var MoveDirection : float = 45;
public var grounded : boolean = false;
function Update(){
if(grounded){
MoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
MoveDirection = transform.TransformDirection(MoveDirection);
MoveDirection *= MoveSpeed;
}
if(Input.GetKeyDown(KeyCode.Space))
{
MoveDirection.y = jumpsSpeed;
}
}
MoveDirection.y -= Gravity * Time.deltaTime;
var Controller = GetComponent(CharacterController);
var Flags = Controller.Move(MoveDirection * Time.deltaTime);
grounded = (Flags & CollisionFlags.CollidedBelow) !=0;
}
as for hit points per speed you would actually have to adjust the script by adding drag to just about everything so that you would be moving different speeds depending on how long the button is held, released, gravity and adding a top speed for acceleration and gravity. Maybe using something like if force = a certain amount then -- hitpoints. sorry i can't be too helpful on that
Or, you could do the smart thing and switch to using rigidbodies ins$$anonymous$$d. The Character-Controller is nice for prototypes, but as soon as you start to need physics for anything, they become extremely difficult to code for.
Yes. I`ll try. But how i know the speed that the character hit something? For example, what function i use to know the relative speed betwen the character and the ground when he falls in abysm?
Your answer
Follow this Question
Related Questions
Collision Problem - Terrain collider remains flat after raising or lowering it 0 Answers
Generated Terrain not colliding! HALP. 0 Answers
Hitting people by a car 3 Answers
Is there any equivalent to composite collider in 3d 0 Answers
Having an array of points(vector2), how do I create a 2d terrain? (new to unity) 2 Answers