x


Constraining 2D movement to polygon surface

Hi guys,

I'm looking to create a 2.5D platformer in which there are certain platforms that the player "sticks" to, and can walk on all sides of. Effectively I want to use the normals of these platforms to tell the player character which way "up" is, and to constrain his movement to these platforms so that he can move left or right all the way around them without falling off.

The problem is that I'm new to unity and I have absolutely no idea where to begin in making this work.

For testing purposes, I'm using a rigid body sphere to represent the player character. If anyone can offer advice to help me get such a sphere to "stick" to a polygon surface and roll around it's edges, that would be very much appreciated!

The following diagram demonstrates what I'm trying to achieve, where the black object is the platform polygon, the blue object is the player character, and the lighter blue objects are example positions the player character can roll around to, ignoring global gravity, etc.

alt text

Any help or advice at all is welcome, no matter how small! I really just have no idea where to begin, and this seems like the kind of thing that other people must have done before.

Thanks in advance,

Hadyn

more ▼

asked Feb 07 '11 at 05:19 AM

Hadyn gravatar image

Hadyn
12 2 2 2

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

1 answer: sort voted first

I'd suggest that for these sections you turn off the global gravity and instead apply your own. Find the edge that the ball is meant to be stuck to and apply gravity along the normal of that edge.

more ▼

answered Feb 07 '11 at 09:59 AM

Damyan gravatar image

Damyan
125 3 4 10

I did think about using gravity to achieve the effect... but my mind, for whatever reason, is reluctant to go that way. I guess I'm seeing the outer edge of the platform as a "path" made up of straight lines, and in my head I'm convinced there should be a really easy way to constrain movement to that "path".

But you've answered my question - the gravity idea is cool and should work. I may consider asking a new question regarding paths and whatnot, but for now - thanks for your advice!

Feb 07 '11 at 01:57 PM Hadyn

Glad to be of service - could you click on the 'tick' to mark this question as answered (if you think it is) :)

Feb 08 '11 at 09:49 AM Damyan
(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:

x1374
x1041
x59
x14

asked: Feb 07 '11 at 05:19 AM

Seen: 1092 times

Last Updated: Feb 07 '11 at 05:19 AM