x


Position of a Collision

I am using a plug-in that handles collision detection of my sprites in a 2D environment. I would like to access the contact.point in OnCollisionEnter, but cannot seem to find a method to extract the information without calling the OnCollisionEnter. Any thoughts?

more ▼

asked Nov 20 '11 at 03:15 AM

Whelandrew gravatar image

Whelandrew
31 15 23 28

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

1 answer: sort newest

Contact points are only reported in OnCollisionEnter/Stay, both occurring in the physics cycle (50 times per second). But if you want to have the contact points available outside these functions, you can make a copy inside them and access the copy in any function:

var contact: ContactPoint; // saved contact point

function OnCollisionEnter(coll: Collision){
    contact = coll.contacts[0]; // save the first contact point
}

Copying the first contact is faster and solves most cases, but you can copy the entire contacts array as well:

var contacts: ContactPoint[]; // contact points saved

function OnCollisionEnter(coll: Collision){
    contacts = coll.contacts; // save contact points
}
more ▼

answered Nov 20 '11 at 03:40 AM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

Yeah, that's right. Thanks for helping me clear my head

Nov 20 '11 at 10:30 PM Whelandrew

Okay... not quite there yet. Orthello2D uses OnTriggerEnter to register collision detection. I can only get contacts through OnCollisionEnter. Can I bridge these two functions?

Nov 22 '11 at 12:39 AM Whelandrew

That's bad - OnTriggerEnter only passes the collider hit, not the hit point. Why do you need the collision point? To determine the impact direction?

Nov 22 '11 at 01:10 AM aldonaletto

A little creature attaches itself to a building upon collision. Right now, I just have the creature setup to attach at the position it is located upon hitting the building. Since the collision point is different than the transform.position, the creature has the appearance of being just slightly off from where it collided. So, it's attached, but it looks like it's floating in the air.

Nov 22 '11 at 01:20 AM Whelandrew
(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:

x2499
x887
x227
x12

asked: Nov 20 '11 at 03:15 AM

Seen: 1068 times

Last Updated: Nov 22 '11 at 01:20 AM