It is currently Fri Dec 06, 2013 11:23 pm

 All times are UTC

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Per-pixel collision and 'bouncing'Posted: Sun Oct 16, 2011 7:21 pm
 Rookie

Joined: Sun Oct 16, 2011 6:45 pm
Posts: 4
I'm looking at making a game that works very differently to the ones I've made previously. Usually I just make tile-based games, but I want to experiment a bit more.

The game I want to make will have a terrain similar to what you've seen in the "worms" games (curved, weirdly shaped hilly type land) which would be predrawn and loaded as an image. I want to have the "bullets" bounce correctly when hitting the terrain.

From my searching it appears the best solution for the collision detection is to use a per-pixel approach. I've looked up some tutorials on it and will have to experiment (if anyone has some suggestions for tutorials on this I would be grateful).

What I'm not sure how to find though is what to use for calculating what angle the 'bullet' should bounce off in when it hits the terrain - or more specifically how to determine what angle the terrain is that it's hitting. I think that what I need to do is grab a square of pixels and somehow calculate what angle they are forming so I can calculate the continued trajectory.

Would this be the correct method or is there a better way to do this?

Top

 Post subject: Re: Per-pixel collision and 'bouncing'Posted: Sun Oct 16, 2011 7:35 pm
 Corpse Bride

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2221
Location: England
hyarion wrote:
Would this be the correct method or is there a better way to do this?

If I remember correctly, worms had strange bouncing and things didn't always reflect as you'd expect them to. It was probably done on a pixel basis. If the missile hits the corner of a pixel, the normal is at that 45 degree angle. If the missile hits the side of a pixel, the normal is at that 90 degree angle.

The way I would do it is to create a search radius ... maybe a square of 8x8 pixels, and calculate it's centre of mass (earth pixel = 0, air pixel = 1). Then calculate the vector from the centre of the square to the centre of mass, and normalise it.

_________________
I ain't pushing no moon buttons.

Top

 Post subject: Re: Per-pixel collision and 'bouncing'Posted: Tue Oct 18, 2011 7:07 am
 Rookie

Joined: Sun Oct 16, 2011 6:45 pm
Posts: 4
Thank you for your advice. Sounds perfect. I have a lot of reading up and testing to do now

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ Forums    Forum Rules and Posting Guidelines Wiki Discussion    Help    Content Issues Game Programming Discussion    C and C++ Game Programming    Java Game Programming    Language Agnostic Programming    .NET Game Programming    VB Game Programming    Mobile Game Programming    Web-Based Game Programming    Other Languages    OpenGL Development    Direct X Development Game Development Discussion    Game Design    Game Media Off-Topic Discussion    Announcements    Off-Topic    Community Projects    News