Solved

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

Posted on 2009-07-13
5
498 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Cited: Konstantinos Dimopoulos URL Cited From: Article from Indie Games: http://indiegames.com/2012/07/browser_game_pick_the_grid.html The Grid (http://codeelf.com/games/grid/) is the sort of game I haven't played in over 10 years. It is …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

636 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