# Thread: New to game making

1. K, the first one I got, but lets take these others a bit slower.
Originally Posted by Bubba
This is a simple vector operation. You can do this several ways. One way is to raycast the bullet instead of having it become an actual object in the world. The raycast is the simple parametric form of a line or P(final) = P(origin) + shoot_vector * distance. Normally you could use the shoot vector to perform a ray intersection test with the bounding volume of your object. Once that passed you would then do a triangle intersection test on the mesh itself to see which ray the triangle hit. Once you computed that you would then compute the barycentric coordinates of the ray intersection within the triangle. From there you would then fire off some type of 'hit' message which would then deduct health, etc.
The terms raycast and parametric mean nothing to me. Vectors I get, but how would I calculate the Shoot_Vector? Other than that, this also makes sense.

Originally Posted by Bubba
In an engine this is handled by the camera class. The player's gun is pointing down the look vector of the camera. To translate the gun to the correct world position you would have a vector in local space that represented the location of the gun relative to the local origin. Then you would multiply the inverse world transpose matrix of the object with the local translation matrix of the gun to move it to the correct location.
Vectors agian? Okay, this is starting to come together! So how does my mouse affect the vector?
The rest I can tackle after theese two.

2. The terms raycast and parametric mean nothing to me. Vectors I get, but how would I calculate the Shoot_Vector? Other than that, this also makes sense.
A 2D raycast is:

Code:
```float final_x = start_x + cosf(angle) * distance;
float final_y = start_y + sinf(angle) * distance;```
A 3D raycast in vector form:

Code:
`Vector3 final = start + unit_vector * distance;`
A unit vector is a vector that has range 0.0f to 1.0f in all three components. This is also known as a normalized vector. You could test final for collision however this is not all that accurate. Actually all you need to do is determine if the unit_vector intersects the bounding volume of the target. Remember that a vector stretches from infinity to infinity so the intersection math works just fine regardless of the magnitude of the vector. If you want to make the bullet 'fly' along the shoot vector you simply normalize the shoot vector and and then multiply it by a distance scalar. The distance traveled is good old distance = rate * time where rate is the speed of the bullet and time is the frame delta or the time it took to render the frame. Keep in mind if you want to 'fly' the bullet to the target you will have to do a completely different collision test to determine if the bullet could hit target X in time interval T. If the interval is infinite then you know the bullet did not hit the target.

Vectors agian? Okay, this is starting to come together! So how does my mouse affect the vector?
The rest I can tackle after theese two.
One way to do it:
Code:
```m_pCamera->Yaw(m_pMouse->GetX() * reduction_factor);
m_pCamera->Pitch(m_pMouse->GetY() * reduction_factor);```
DirectInput will return mouse coordinates in relative by default so this works fine. If your particular mouse driver or API returns them in absolute you will have to derive the relative via a simple subtraction from the last known mouse x and y.

There are other more sophisticated methods such as converting the mouse x,y to spherical coordinates or mapping them to a unit sphere and then adjusting the up, look, and right vectors accordingly.

3. Okay, I'll see where this gets me and get back to you.