- Home /
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.
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
Hey just wondering if you even solved this issue .. I've been looking for the exact same thing but can't seem to figure out how to do it.
Did you try the gravity-based solution suggested in the answer?
Sorry but noob alert. I'm not really sure how to get the normal of the surface. I know it needs raycasting but I've never used it so might need some help with that if possible :) .. and after I do get the normal could I possibly even tilt my player according to the angle? .. I know nothing about raycasting .. will this give me an option to not freeze my Z axis? ..
Answer by Damyan · Feb 07, 2011 at 09:59 AM
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.
I did think about using gravity to achieve the effect... but my $$anonymous$$d, 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!
Glad to be of service - could you click on the 'tick' to mark this question as answered (if you think it is) :)
Your answer
Follow this Question
Related Questions
How to limit the directions an object can move? 2 Answers
Player rotation affecting Top Down 2D Movement 1 Answer
Character movement problem, floats away 1 Answer
Making side-scrolling movement? 0 Answers
Character doesn't jump repeatedly 1 Answer