Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-07-13
5
Medium Priority
?
510 Views
Last Modified: 2013-12-27
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
Comment
Question by:Valleriani
  • 2
  • 2
5 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 24843615
sqrt( (Xvelocity1 -Xvelocity2)^2 + (Yvelocity1 - Yvelocity2)^2 )
0
 
LVL 3

Expert Comment

by:SordSord
ID: 24843944
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
 
LVL 7

Author Comment

by:Valleriani
ID: 24844065
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
 
LVL 3

Accepted Solution

by:
SordSord earned 1000 total points
ID: 24844628
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
 
LVL 85

Assisted Solution

by:ozo
ozo earned 1000 total points
ID: 24845974
the relative velocity between v = < -2 , 3> and u = < 4 , 6>
= sqrt( (-2 - 4)^2 + (3 - 6)^2 ) = sqrt(45)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question