Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411508 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 26, 2024, 08:46:04 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Object collision based on vectors & spheres
Pages: [1]
Print
Author Topic: Object collision based on vectors & spheres  (Read 827 times)
r0ber7
Level 2
**


i like games


View Profile WWW
« on: June 07, 2013, 05:53:10 AM »

Consider this.

I've based this on this article, which I only understand somewhat.
http://www.wildbunny.co.uk/blog/2011/04/06/physics-engines-for-dummies/



To check collision between two spheres, I calculate the distance between the two centers of those spheres. If that distance is smaller than the sum of the radiuses plus the velocity of the objects (r + r + xs), collision = true.

My question is about collision with the ground. I have an array with x&y locations for the ground. I know the position of a, I know the position of b, I know the length of r, I know the velocity of the object along the vector, so I know point c too.

How do I check if b,c intersects with d,e? I've read about the dot product, but I don't really understand how I would implement that. I'm fairly new to vectors, and I hope someone here can help me.

Cheers.

Logged

BleakProspects
Level 4
****



View Profile WWW
« Reply #1 on: June 07, 2013, 07:26:58 AM »

Line sphere intersection:

http://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection

You can also compute the closest point along the line to the sphere's center and see if its distance is less than the sphere's radius:

http://stackoverflow.com/questions/3120357/get-closest-point-to-a-line
Logged

r0ber7
Level 2
**


i like games


View Profile WWW
« Reply #2 on: June 07, 2013, 10:16:40 AM »

Line sphere intersection:

http://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection

You can also compute the closest point along the line to the sphere's center and see if its distance is less than the sphere's radius:

http://stackoverflow.com/questions/3120357/get-closest-point-to-a-line

Thanks, it's working. Smiley You just made my day.
Logged

Evan Balster
Level 10
*****


I live in this head.


View Profile WWW
« Reply #3 on: June 07, 2013, 12:54:30 PM »

How do I check if b,c intersects with d,e?

Be advised that this is not always true when the circle collides with the line.
Logged

Creativity births expression.  Curiosity births exploration.
Our work is as soil to these seeds; our art is what grows from them...


Wreath, SoundSelf, Infinite Blank, Cave Story+, <plaid/audio>
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic