Solved

Sprite collision detection

Posted on 1997-11-12
1
187 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now