The segment array ground vs player(box) on top of it thing

Official forum for the Chipmunk2D Physics Library.
Post Reply
lumni
Posts: 2
Joined: Sun Feb 23, 2014 4:13 pm
Contact:

The segment array ground vs player(box) on top of it thing

Post by lumni »

Hi
I'm having this problem with my character getting stuck on ground (an array of segments).
I searched the other topics and found some really old ones, and something about this being perfected in 6.2, i tried using cpSegmentShapeSetNeighbors and changing the radius but nothing seems to change.

Code: Select all

for(int i = 2; i < nsegs-1; i++){
        cpSegmentShapeSetNeighbors(ground[i-1], cpSegmentShapeGetB(ground[i-2]), cpSegmentShapeGetA(ground[i]));
is this the right way to use it ?
sorry if my question is too dumb, im new to chipmunk
great engine by the way.
lumni
Posts: 2
Joined: Sun Feb 23, 2014 4:13 pm
Contact:

Re: The segment array ground vs player(box) on top of it thi

Post by lumni »

i have found a solution to my problem but it wasnt related to what i thought it was, i'll explain just in case someone has the same problem.

first, that was not the right way to use that function (probably, since i didnt notice any effect).
second, that was not needed. the start point of a segmentShape was exactly the end point of the previous one and so on.
third, my character was not stuck on ground, it just couldnt jump sometimes and i didnt know why (i was using an inAir flag which i updated with the collision begin and separate callbacks).
the problem was, i setted the inAir flag to 1 every time the player separated from the ground, and setted to 0 again on begin. if the flag was 0, the player was allowed to jump. but if i started walking to the left or to the right, the player would then step in the next segment shape (begin callback would be called) and when it stepped out of the segment it was on top previously, separate would be called and that would set my flag to 1, so my player couldnt jump even though he was standing on the ground.
the solution is simply change the flag from bool to int and increment it on begin, decrement on separate, allow jump if != 0.

i know, stupid problem, but took me some time to figure it out. maybe this helps someone.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests