x


OnCollisionEnter() help

heres my script

function OnCollisionEnter (Collision : Collision){

Application.LoadLevel ("Cave");
}

i have it attached to my door but when i walk onto my door (its at an angle) nothing happens except one time it worked, do i have to specify what it is colliding with?

more ▼

asked Sep 12 '11 at 08:26 AM

sam32x gravatar image

sam32x
178 42 57 63

try to change your variable name Collision

Sep 12 '11 at 09:20 AM Mai hime

what variable?

Sep 12 '11 at 09:26 AM sam32x

Collision: Collision => hit:Collision

Sep 12 '11 at 10:12 AM Mai hime
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Try doing:

 function OnCollisionEnter (other : Collision){

Application.LoadLevel ("Cave");
}
more ▼

answered Sep 12 '11 at 09:43 AM

Ludiares gravatar image

Ludiares
210 2 3

It's a bit confusing to name the Collision "other" as it is a reference to the collision, not the other object. The trigger Collider is on the other hand a reference to the entering object.

Sep 12 '11 at 10:41 AM save
(comments are locked)
10|3000 characters needed characters left

I would use tags for this one. Also dont forget to add the script to the trigger object and Player should have "Rigid Body" physics.

function OnTriggerEnter(hit : Collider)
{
if(hit.tag == "Player")
{
  Application.LoadLevel("Cave");
}
  else { return; }
}
more ▼

answered Sep 12 '11 at 12:37 PM

warkarma gravatar image

warkarma
31 1 1 3

(comments are locked)
10|3000 characters needed characters left

Make sure you have the scene name ("Cave") in your Scene Building Column!!!

more ▼

answered Sep 12 '11 at 01:20 PM

henry96 gravatar image

henry96
597 16 20 23

yes i have it

Sep 13 '11 at 03:19 AM sam32x
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x57

asked: Sep 12 '11 at 08:26 AM

Seen: 685 times

Last Updated: Sep 13 '11 at 03:19 AM