• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Basic Physics of 2d Collisions

Status
Not open for further replies.
Level 10
Joined
Feb 7, 2005
Messages
409
so first off, I don't know anything about physics, I have tried many times to google it, to teach my self, to ask around etc.

As far as I know, and have been told, this is a very basic and simple equation, but no one has told me wtf this "basic and simple" equation is.

I really, really, just need the function. I don't need to given links to sites, or told that I should just research it etc, just need the function. If you don't feel like providing it, please don't bother to post.

Given:

soo basically, I have an object moving at 5cm per 0.05 sec, heading in a direction of 38 degrees on a two dimensional plane (both objects have a mass of 1 for arguments sake if that helps). Said object collides with another object that is travelling in the direction of 112 degrees with a speed of 8cm per 0.05sec.

I need a function that will return the new angle and speed of whichever object I choose after collision. Preferably this function could be used to determine collision between one moving and one immovable object as well etc. Pretend that there is no outside forces acting upon them except for this simple collision of force, as it is within the game world.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
From: http://www.hiveworkshop.com/forums/jass-ai-scripts-tutorials-280/deflection-angle-194703/
JASS:
// Returns angle in radians
function GetDeflectionAngle takes unit missile, unit target returns real
    return 2.*Atan2(GetUnitY(target)-GetUnitY(missile),GetUnitX(target)-GetUnitX(missile))+bj_PI-GetUnitFacing(missile)*bj_DEGTORAD
endfunction

// Wrapper, returns angle in degrees
function GetDeflectionAngleDeg takes unit missile, unit target returns real
    return bj_RADTODEG*GetDeflectionAngle(missile,target)
endfunction
You can use this in case objects don't lose speed on collision.
 
Level 10
Joined
Feb 7, 2005
Messages
409

"I don't need to given links to sites, or told that I should just research it etc" thanks anyways I know you're just trying to help.

giving Garfields thing a shot.
 
there are two ways I know of to reflect a circle-shape hitting a wall but both have in common that the angle of incidence is equal to the angle of reflection

you can do it with trigonometry or with vectors
if you know trigonometry you can derive the formula yourself
if you don't you could ask the forum search (which sucks but you might be lucky)

the second way uses a formula like this:
reflection vector = incidence vector - 2*wallNormal*(wallNormal dot incidence vector)
wallNormal must be normalized

I did not find an easy solution like this for rotating non-sphere objects yet
if you do please tell me
 
http://http.developer.nvidia.com/Cg/reflect.html

103505d1309986189-basic-physics-2d-collisions-reflectionvector.png
 

Attachments

  • reflectionVector.png
    reflectionVector.png
    14.6 KB · Views: 233
Status
Not open for further replies.
Top