[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 511
  • Last Modified:

Game Physics - Proper way to figure out collision velocity? (Math Gurus!) Relative Velocity!

Ok so I have a space game, at the moment in the works.

I am having one issue with a weapon, or rather, I'm not sure how I should do this. However, this is how it works:

I have a 'ram' ship weapon, where your ship can damage if you 'ram' (run into) another ship.  However, currently ram damage is depending how how 'fast' you are going.

However, the problem is, people bring up that it should get a relative velocity. What I mean is Ship 1 minus (or plus) Ship 2 velocity, but depending on heading/etc etc.

Generally, for example, If I was going 0.90GU/s behind a ship that was going 0.80GU/s if the heading was the same, the velocity would become only 0.10GU/s. However, if we were 'running into each other' with total opposite headings (Aka I'm going north and hes going south.) and we collided, the velocity woudl be 1.70GU/s.

However, the issue becomes when headings aren't exactly the same, maybe one ships going SE, and I'm charging him from the EAST. How would I determine the proper damage? My game uses basic X/Y, heading, current speed etc. Basicly speed however is determined by X/Y coords and such. There are a few other variables that relate to movement.

Does anyone have a good tip or idea/formula I should use here? I would think it would use heading and X/Y + current speed only to determine the relative velocity, but I'm not too sure. I'm not asking for a full code example, but rather, a formula or tip on how this should work thats more broken down/easy to understand.

I am new to game physics so I am learning myself. Thanks!
0
Valleriani
Asked:
Valleriani
  • 2
  • 2
2 Solutions
 
ozoCommented:
sqrt( (Xvelocity1 -Xvelocity2)^2 + (Yvelocity1 - Yvelocity2)^2 )
0
 
SordSordCommented:
I'm thinking you might want to calculate the dot product of the two vectors and subtract from the ramming ships speed.

Doing so will result in a lower collision speed if the target is running away from you, a higher if it is heading towards you, and no change in speed if it is just crossing in front of you.

Contract to adding the vectors (ozo's suggestion), which will cause a fast moving target that side swipes a nearly stationary ram to take the same damage as if the ram were moving it's speed and it was stationary.
0
 
VallerianiAuthor Commented:
Yeah, I'd definatly like to make sure for checking collision speed depending on angle etc. In a sense with X/Y etc how would this work out? I looked about and the easiest one I found is:

v = < -2 , 3> and u = < 4 , 6>
= (-2)*(4) + (3)*(6) = -8 + 18 = 10

For example, and I guess V and U would be Ship1, and Ship2, lets say, for example.  But I don't think this is what you were meaning/etc.
0
 
SordSordCommented:
Oh, I should have said scalar projection, which is the dot product/vector length. In your example, if v is the ram ship and u is the target.

v is moving at sqrt(13) or about 3.6
The scalar projection is 10 / 3.6 = 2.77
Giving a collision speed of 3.6 - 2.77 = 0.83
0
 
ozoCommented:
the relative velocity between v = < -2 , 3> and u = < 4 , 6>
= sqrt( (-2 - 4)^2 + (3 - 6)^2 ) = sqrt(45)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now