hey
I have a problem with my “move around” script for my character
there are problems in the function OnControllerColliderHit
my script looks like this
//Moving around
var speed = 3.0;
var rotateSpeed = 3.0;
//Shooting
var bullitPrefab:Transform;
//Dying
static var dead = false;
//Geting hit
var tumbleSpeed = 1000;
var decreaseTime = 0.01;
var decayTime = 3;
static var gotHit = false;
private var backup = [tumbleSpeed, decreaseTime, decayTime];
function LateUpdate()
{
if (dead)
{
transform.position = Vector3(-1.2,1.1,-40);
gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
dead = false;
}
if (gotHit)
{
if(tumbleSpeed < 1)
{
//we're not hit anymore... reset get back in the game!
tumbleSpeed = backup[0];
decreaseTime = backup[1];
decayTime = backup[2];
gotHit = false;
}
else
{
//we're hit! Spin our charavter around
transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
tumbleSpeed = tumbleSpeed-decreaseTime;
decreaseTime += decayTime;
}
}
}
function OnControllerColliderHit(hit :ControllerColliderHit) : void
{
if(hit.gameObject.tag == "fallout")
{
dead = true;
//substract life here
HealthControll.LIVES -= 1;
}
if(hit.gameObject.tag == "fiendeball" )
{
gotHit = true;
HealthControll.HITS +=1;
Destroy(hit.gameObject);
}
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
//shooting!
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab,
transform.Find("spawnpoint").transform.position,Quaternion.identity);
bullit.tag = "wormball";
bullit.rigidbody.AddForce(transform.forward * 5000);
}
}
@script RequireComponent(CharacterController)
I’ve tested most of the collider functions
I may not have got them right but I do not know
my fallout works but not getting hit by cannon. it works only sometimes
(fallout is when I fall out of the platform)
I need a function that works for getting hit by a ball
please help me
//txzzo
OnControllerColliderHit works OK when the character moves into something else, but doesn’t detect when an incoming object hits the character. Assuming the ball is a rigidbody object, try putting the hit detecting code in the ball’s OnCollisionEnter function. You can use SendMessage to call a function on the character after the hit:-
function OnCollisionEnter(coll: Collision) {
coll.transform.SendMessage("ReactToHit");
}
Fortunately, because if not, everyone could make a game.
You could have problems with a nail, with your hammer or trying to find out which is the best way use a hammer fast and with precision… but you must know how to hammer.