x


The rotation of an object in relation to ground

Hello, I'm making a little ski game and I want to have crash detect. So if you land too sideways it will trigger the crashing animation. How can I read what the rotation of the character is in relation to the normals?

Let's say the crash tolerance is 45 degrees. The character is rotated 45 degrees but the ground is also at a 45 degree slope meaning the sum of the two would be 90, making the character land on his side. Here's a little diagram of what I mean:

alt text

PS he's not pissing blood, that's a raycast :)

example.jpg (34.1 kB)
more ▼

asked Jun 11 '12 at 05:48 PM

commodore gravatar image

commodore
113 8 22 30

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

1 answer: sort voted first

OnCollisionEnter (when the player touches the slope) provides you the normal at the impact through CollisionInfo.ContactPoint. I suggest you calculate the dot product between that normal and transform.up (of the player). If it is > 0.7 for instance, the landing is safe. Reminder : angle = acos(dotproduct).

Or you could use Vector3.Angle.

PS : Awesome drawing :p

more ▼

answered Jun 11 '12 at 06:18 PM

Berenger gravatar image

Berenger
11k 12 19 53

Thanks! I'll mess around with it when I get home.

Jun 11 '12 at 06:22 PM commodore

Try out Ski Safari by the, it's great !

Jun 11 '12 at 06:31 PM Berenger

Man that's fun! I'll be sure to show you my game once it's done

Jun 11 '12 at 06:42 PM commodore
(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:

x1530
x125
x83

asked: Jun 11 '12 at 05:48 PM

Seen: 504 times

Last Updated: Jun 11 '12 at 06:42 PM