Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411651 Posts in 69395 Topics- by 58451 Members - Latest Member: Monkey Nuts

May 15, 2024, 10:52:25 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Need help with forced Collisions
Pages: [1]
Print
Author Topic: Need help with forced Collisions  (Read 1020 times)
pdyxs
Level 0
**



View Profile WWW
« on: August 26, 2010, 04:37:39 AM »

Hi all,

I'm currently working on a game where two players control spheres in an asteroid-like control scheme, which bounce off each other like billiard boards.

I'm having no problems with the maths for the collisions themselves, but am having issues with a few specific cases and ordering of operations.

Essentially, each ball has a velocity and a force vector (the player control) being applied to it. At the start of a frame, I go through and calculate the dx and dy for each ball based on the force and velocities. At the moment, I'm then doing collision detection based on their theoretical final position, but only moving them if they don't collide (and calculating new velocities if they do). Essentially, if there's a collision, the balls don't move in that frame.

The issue is that sometimes, this means that they simply stop moving altogether, as the new velocities being calculated are still resulting in a collision on the next frame (this often happens when they're moving slowly when they collide).

The other way (in which I move them whether they collide or not) often results in wild behaviour where collisions are detected in every frame and the spheres go flying...

The option exists to do further calculation to work out the exact point of collision, splitting the frame into the time before the collision and the time after (using old velocities before, and new ones after), but that seems more complex than it really needs to be.

Anyone have any solutions to this?
Logged

Corporate Cosmologist at Throw the Looking Glass, where we're making Particulars using the SCIENCE! methodology.

http://www.throwthelookingglass.com/
zacaj
Level 3
***


void main()


View Profile WWW
« Reply #1 on: August 26, 2010, 06:42:03 AM »

Heres a few links.  I think youre looking for swept/continuous collision detection
http://www.gamasutra.com/view/feature/3015/pool_hall_lessons_fast_accurate_.php
http://twobitcoder.blogspot.com/2010/04/circle-collision-detection.html
Logged

My twitter: @zacaj_

Quote from: mcc
Well let's just take a look at this "getting started" page and see--
Quote
Download and install cmake
Noooooooo
pdyxs
Level 0
**



View Profile WWW
« Reply #2 on: August 26, 2010, 08:05:21 PM »

Thanks! I'll give that a go and let you know.
Logged

Corporate Cosmologist at Throw the Looking Glass, where we're making Particulars using the SCIENCE! methodology.

http://www.throwthelookingglass.com/
harima555
Level 0
**


View Profile
« Reply #3 on: August 27, 2010, 01:55:22 PM »

What exactly are you doing when you detect a collision?, you say that youre changin the velocities of the balls but are you changing the direction of the force vector as well?, it seems to me that your collision code should modify the direction of the force vector (not just the speed), if the direction of the force vector does not changes there will be a collision on the next frame for sure. 
Logged

If learn programming does not make you feel dumb,you´re doing it wrong
bateleur
Level 10
*****



View Profile
« Reply #4 on: August 28, 2010, 11:20:16 PM »

Incidentally, if you still wanted an easier method than swept collision detection, what you can do is make the move, detect any collision and then push the spheres apart enough to eliminate intersection.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic