Solved

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

Posted on 2009-07-13
5
474 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 84

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 250 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 84

Assisted Solution

by:ozo
ozo earned 250 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now