Solved

Sprite collision detection

Posted on 1997-11-12
1
192 Views
Last Modified: 2010-04-10
I'm currently writing a game in which you control a little
character with a gun.  But I was wondering how I could detect wether or not the character is standing next to a wall.  Right now, the character runs through the wall.  I've used the div function to check the sector next to the character to see if its blank, however, the character can move into the next sector before he is "in" the next sector and thus is drawn half way in the wall.  How can I detect if the character can walk to the right or left?
0
Comment
Question by:pbinsted
1 Comment
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1173106
Generally, two different objects cannot occupy the same position in space. One way to know if something is going to collide is to compare the two rectangles for the objects. If there is an intersection between the two rectangles, then there is a collision. To detect if something is going to collide, then you would use the imagined new positions for the moving objects and intersect them. If there is an intersection, then the new positions cannot happen.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question