Sticking to a wall

Official forum for the Chipmunk2D Physics Library.
Post Reply
blejzz
Posts: 2
Joined: Mon Oct 28, 2013 8:16 am
Contact:

Sticking to a wall

Post by blejzz »

Hello,

I am new to the chipmunk and its forum. I am working on a game where the main hero is a ball and can move on terrain which is made out of segment shapes. The ball is moved by setting its angular velocity (so you can't throw it in the air). Now i would like to enable that the ball can stick to the terrain and when you move it, it should follow the terrain outline. So for instance if you have a cliff and you move the ball of the cliff it wouldn't fall off but move along the vertical edge or if you have a wall it should climb up a wall.

What i would like to archive is that if you move it of a cliff it should move in the same way as it would on flat ground. What would be the simplest way to do this? My idea was to change the gravity vector when colliding with the segment in the direction of the segment, but the problem is that when moving of a cliff it would fall off since my collision handler gets called only when colliding with the horizontal segment and not the wall segment (the cliff is made out of two segments a horizontal one and a vertical one that makes the wall). And i cannot offset the segments since they are created dynamically. Is there any other way of doing this, perhaps with a constraint?

Thanks!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Sticking to a wall

Post by slembcke »

So one of the Chipmunk demos is called "sticky". It uses the user data property of arbiters to store a constraint that sticks objects together when they collide. This might be sort of useful to you.

I think something that would work better in your case is to attach a pivot joint between the world and your player object. You can give the pivot joint a pre-solve callback which updates the joint just before Chipmunk figures out all the collision and joint forces. You can use that to recalculate where the player is touching the ground and put the joint's anchors there. Nearest point queries with some layer filtering would make that fairly easy to do.

Those are the two ideas I can think of off the top of my head.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
blejzz
Posts: 2
Joined: Mon Oct 28, 2013 8:16 am
Contact:

Re: Sticking to a wall

Post by blejzz »

thanks for the help, i've used a slide joint instead (had less trouble setting it up) and changed the gravity vector so the ball doesn't fall off when climbing vertically.
Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests