Collider problem (420716)

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");
}

now its look like this and my error code this (54,1): BCE0044: expecting :, found 'dead'

the script part looks like this:

function OnCollisionEnter(coll: Collision) { 
coll.transform.SendMessage("ReactToHit"); 
{
(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);
}
}

what do I need to change?

///txzzo

The line…

(hit.gameObject.tag == "fallout")

would be…

if (hit.gameObject.tag == "fallout") {

i gues… i didn’t read the code O_o

well the dead part is gone but now I have

BCE0043: Unexpected token: if.
BCE0044: expecting :, found '='.

You have several errors; fix all of them.
I guess you code now looks like this:

function OnCollisionEnter(coll: Collision) {
coll.transform.SendMessage(“ReactToHit”);
{ → erase this!
if (hit.gameObject.tag == “fallout”) {

dead = true;
//substract life here
HealthControll.LIVES -= 1;
}

if(hit.gameObject.tag == “fiendeball”); → erase this semicolon
{
gotHit = true;
HealthControll.HITS +=1;
Destroy(hit.gameObject);
}
}

hm just one error now

 BCE0044: expecting EOF, found '}'.

I need a { at some place but where?
script looks like this:

function OnCollisionEnter(coll: Collision) { 
coll.transform.SendMessage("ReactToHit"); 

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);
}
}

Yes… looks like you are doing wrong.
Watch my previous post and delete what i pointed.

greets.

do anny one know whats wrong?

txzzo, change…

if (hit.gameObject.tag == "fallout");

for this…

if (hit.gameObject.tag == "fallout") {

hm well now its another error when I did change it.

function OnCollisionEnter(coll: Collision) { 
coll.transform.SendMessage("ReactToHit"); 

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);
}
}

the error is:

(63,9): BCE0005: Unknown identifier: 'hit'.

(52,5): BCE0005: Unknown identifier: 'hit'.``(59,4): BCE0005: Unknown identifier: 'hit'.

Don’t get wrong… or yes (as you wish), but you don’t have problems with your code; you can’t understand that code… that is the problem.

The error says Unity can’t recognises “hit” idetifier, and that is because you called it “coll”; you must change one of those.

My suggestion: try to learn basics of development.

maby I shod stop making games than if I dont understand anny thing :frowning:

Just try to learn basics, because the develop of your game will be stopped because of several issues like:

  • Simples errors.
  • Not knowing how to do whatever you need.

anny way I get it to work thanks

I know I need to learn theme but its hard…

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.