Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Hills
- - By kansha Date 2015-05-27 09:46
I am very new to game development. I started work on a side scroller in Ruby using Gosu. Very quickly I decided to add Chipmunk, as building my own physics engine was getting involved. The problem is, hills. My player sprite stops or bounces with enough velocity at the edge of the a hill. I found a reference here:

http://chipmunk-physics.net/forum/viewtopic.php?t=287

The problem is that beveled edges was added in 6.2, and the Ruby GEM of Chipmunk uses 6.1.

Is there any way I can fix this in Ruby? I considered switching to C++ but its been years since I made anything in C++ and development time would be slowed down.
Parent - - By lol_o2 Date 2015-05-27 14:36
It's easy to make hills both in C++ and in Ruby, but I don't use Chipmunk, so I don't know how is it in there.

I can explain it, using some code from Cptn, Ruby (one of Gosu examples)

Here's how it looks without hills:
if move_x > 0
    move_x.times do
        if would_fit(1, 0)
            @x += 1
        end
    end
end


And with hills:
if move_x > 0
    move_x.times do
        if would_fit(1, -2)
            @x += 1
        end

        2.times do
            if !would_fit(1, 0)
                @y -= 1
            else
                 break
            end
        end
    end
end


Basically, when you move your character horizontally, you check if there's no wall on the side. But if you want to take care of hills, you can't check walls at the bottom of the character, but let it overlap. Then if bottom of sprite overlaps some ground, just move the character up. Of course you need to do this per each pixel, so if character moves 1 pixel right, it has to check ground before moving next pixel. You can also make character "stick" to downhills similar way.
Parent - By kansha Date 2015-05-28 18:37
Thanks for the reply. I know I can do a pixel based system like this, as that is what I was doing before. The problem is I was having to reinvent a lot of wheels like calculating the rotation of the sprite when doing up a hill, collision detection, etc. Using a 2d physics engine has saved me the trouble.

I kinda of figured out a sort-of-fix for my problem. By setting moment of inertia to a high value (10,000) the polygon is resistant to rotating easily and doesn't jump over corners on line segments that make up slopes. Rounded would still be better. But near as I can tell I would have to draw arcs and lines connecting to those arcs. And I am still rusty on my trigonometry.
Up Topic Gosu / Gosu Exchange / Hills

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill