• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Collision Line with Box

This topic is 5885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, at the moment I am programming my collision detection. I wonder what possibilities there are to detect a collision between a line (Points: P1, P2) and a Box (Points: B1-B8) Right now I got a algorithum that is only good on high frame rates because I test if P1 is INSIDE the box or P2 is inside the Box. Although i think i need a old Position value to eleminate the "jump" of my laser - I mean if the Framerate drop below 40 (on older PC''s) I have the effect that the enemy is never hit because the (fast) laser that is infront of the enemy jumps behind the enemy and there is no collision detected. So I thought of a "oldPos" info in the laser (this is P2) so I can determine if a laser''s travled way made a collision with a enemy. due to the enemy (low against the laser - problably ration: 1:5) speed it is not nessesary to determine the time acpect (I think) - if it is needed (if a ship where hit even if it was not realy at a point i could have been hit I will see what I need to do then) So how to determine if a Line hits a Box at any Point of the Line. - One way I think of is a for loop but thist is to CPU hungry I think. (how that people are able to understand my situstion and questions) thank you

##### Share on other sites
is your box an aabb or an obb ?

if you are using obb, you will probably need an algo to detect collisions between 2 obb. Then you can just see your line as an obb with 2 dimensions reduced to 0 . So you just have to apply your obb-algo to this stange obb. ( and to make it faster, dont test null-axis. )

and well, if it''s an aabb you can still do the same thing (but there is probably something faster)

Tang

##### Share on other sites
AABB is unrotated and OBB is rotation with the object right?

thank you.

But the main thing how to determine if a line goes though this is not answered with this - or am i missing something out?

and what about bouncing speheres - they would be the fastest way to determine, aren't they?

But as I said the main issue that I need to clear out is how to determine that the enemy is hit if the framerate is to low to have enough tests/secound and the laser jumps from one point to another without comming to close to an enemy.

[edited by - Dominik_78 on December 6, 2002 1:47:06 AM]

##### Share on other sites
>AABB is unrotated and OBB is rotation with the object right?
yes, that''s it

>But the main thing how to determine if a line goes though this >is not answered with this - or am i missing something out?

the colliding algo of obb (or aabb , or spheres) can be easily extended to check wheter 2 boxes with a linear velocity collide during a duration t. So it can answer your problem.

>and what about bouncing speheres - they would be the fastest >way to determine, aren''t they?

well, I suppose it depends of your application. a single test between spheres is certanly faster, but you may need more tests to get the same accuracy.

Tang

##### Share on other sites
>AABB is unrotated and OBB is rotation with the object right?
yes, that''s it

>But the main thing how to determine if a line goes though this >is not answered with this - or am i missing something out?

the colliding algo of obb (or aabb , or spheres) can be easily extended to check wheter 2 boxes with a linear velocity collide during a duration t. So it can answer your problem.

>and what about bouncing speheres - they would be the fastest >way to determine, aren''t they?

well, I suppose it depends of your application. a single test between spheres is certanly faster, but you may need more tests to get the same accuracy.

Tang

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634044
• Total Posts
3015215
×