Modify position, normal, and depth of collision

Chipmunk2D Bindings for the Unity3D engine
Post Reply
Exploding Rabbit
Posts: 14
Joined: Wed Dec 04, 2013 3:31 am
Contact:

Modify position, normal, and depth of collision

Post by Exploding Rabbit »

I noticed some functionality documented in the manual that is not available in the Unity version.

Code: Select all

cpContactPointSet cpArbiterGetContactPointSet(const cpArbiter *arb)
void cpArbiterSetContactPointSet(cpArbiter *arb, cpContactPointSet *set)
Any plans to expose this? It would be very useful!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Modify position, normal, and depth of collision

Post by slembcke »

I've thought about it. The problem is that it would require a frustrating large amount of code to pass the cpContactPointSet type back and forth between C and C#. The get functionality is exposed through the other arbiter methods, and the set method is very rarely used.

What did you have in mind to do with it? It's very powerful, but it's also very easy to completely break a the solver with it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Exploding Rabbit
Posts: 14
Joined: Wed Dec 04, 2013 3:31 am
Contact:

Re: Modify position, normal, and depth of collision

Post by Exploding Rabbit »

I'm creating a retro style 2D platformer, and my player is capsule-shaped. Let's say the player is standing on some ground with an angle of 45 degrees. If the player jumps straight up and lands back on the ground, the player's position is shifted slightly because the normal is perpendicular to the ground. I'd like for the normal to always point straight up so that the player will always land directly above the point they penetrated the ground at.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Modify position, normal, and depth of collision

Post by slembcke »

Unfortunately I think modifying contact points is not very intuitive. If you change the normal to always be upwards, then it will be impossible for the incline to push you in an upward direction and you'll just plow through it. When I've used the feature in the past, I've ended up with some confusing results. (unwanted rotations, surfaces that mush together, etc) Had to sit and think about exactly what it was I was telling the solver with the modified contacts.

I think you might be able to do what you want if you modify the contact points and depth, and reject the collision as appropriate though.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Exploding Rabbit
Posts: 14
Joined: Wed Dec 04, 2013 3:31 am
Contact:

Re: Modify position, normal, and depth of collision

Post by Exploding Rabbit »

slembcke wrote:I think you might be able to do what you want if you modify the contact points and depth, and reject the collision as appropriate though.
Are you just saying I should position the player manually using the information from the collision, or is there some functionality you're speaking of that I am unaware of? I thought I'd have to move the player myself if I didn't have access to cpArbiterSetContactPointSet.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Modify position, normal, and depth of collision

Post by slembcke »

Well, I mean if you did have access to cpContactPointSet it might be possible to get the effect that you want, but not as simple as changing the collision normal. I think you are still going to run into issues with walls. While you want the feet to be sampled as a smaller point, you still want the width of the shape to be as wide as the player when standing against walls.

I've always been able to find a happy medium between tweaking the size of a collider and the alignment I want it to have with the graphics, but I'll have to think about this.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Exploding Rabbit
Posts: 14
Joined: Wed Dec 04, 2013 3:31 am
Contact:

Re: Modify position, normal, and depth of collision

Post by Exploding Rabbit »

I didn't mean I was only going to change the normal. I was just using that as an example because it was the easiest way to explain it. I figured I'd have to modify all three parts of the cpContactPointSet.

I'm not sure what it has to do with walls. I was only going to modify things while the player is standing on ground. If the player jumps into a corner or wall, the regular resolution of the collision should work fine. Also, I wasn't planning on having the "feet" be a separate part of the player. It's just one shape, and it's currently a capsule.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests