Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
c++ syntax question 9 66
HTTPSendRequest with WinINet delays on first call 11 119
Will either laptop run DayZ? 2 160
Lego Star Wars on Windows 10 3 141
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…
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

734 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