Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bullet path

Started by Illasera Aug 26, 2008 at 12:10 PM 3 replies 1.5k views
Original Post
Illasera
Illasera
Hey, I have seen a lot of topics related to bullet tracing, trajectories of projectiles and more, But its all a bit complex for what am looking for is considered "simple", Am looking for a way to get a bullet to proceed forward from the current client origin, No forces affect the bullet path, The bullet isn`t even based on time factor (yet), the bullet should proceed forward by a constant number with each passing frame. This is my code so far, only the forward direction, its nice that i have the direction, but how do i keep the bullet going into that direction, from the current player position?


void ACTIVE_WEAPON::GET_BULLET_TRACE()
{
	VECTOR_3D<float>SAMPLE(0,0,0); // A simple 3D space vector contains
// X, y, z

	float R = sqrt(pow(PTR_CAMERA->ROTATED.m_y, 2) + pow(PTR_CAMERA->ROTATED.m_x, 2)); // Normalization

	SAMPLE.m_x = M_WEAPON_ANGLE.m_x = (-PTR_CAMERA->ROTATED.m_y / R);
// X forward
	SAMPLE.m_y = M_WEAPON_ANGLE.m_y = (PTR_CAMERA->ROTATED.m_x / R);
// Y forward
	SAMPLE.m_z = 0;

	M_BULLET_TRACE = SAMPLE; // Convert temp SAMPLE vector into M_BULLET_TRACE which is also a vector.

	M_BULLET_ALIVE = true; // Should be set to false when collided, as long
// As its toggled to true, keep the bullet updated to proceed forward
};

void ACTIVE_WEAPON::UPDATE_BULLET()
{
// I tried few things here, some equations related to position calculation, but not much luck
        return;
};




davek20
davek20
If I understand your question, it seems that you want the bullet to take into account for the player's velocity, right? For example(2D), say the player is running to the left, and fires a bullet up, the bullet's actual path will be in the up-left direction.

All you need to do is any time a bullet is fired, just add the player's current velocity to the bullet's velocity. Then each time you update the bullet, just add the velocity to the position to get the new position.
Illasera
Illasera
Am not sure i quite understand you, sorry :(

I am not looking for bullet nor player velocity, Right now if i so called (fires a bullet) The bullet is going straight forward to the given direction, However, it goes from the default location of space, the space origin(0,0,0), Now assuming that the player is standing at (5.0, 2.0f, 0.0) and shoot forward, and the shot is been triggered from the world origin, the end position and the path will be inaccurate, since the path was made from the Zero location and not the players location.

so am not sure i quite get you since i dont have a velocity factor yet.
juuso
juuso
I may have missed your point, but it seems like you just need to set the bullet's starting position to the player's position.

So, to create a bullet:
bullet.position = player.position; // position is a vectorbullet.direction = player.direction; // direction is a vector


And to update the bullet each frame:
bullet.position += bullet.direction * BULLET_MOVEMENT_PER_FRAME;


Replace the BULLET_MOVEMENT_PER_FRAME with some (small) number. That should get you started. But you really should use a velocity for the bullets. Otherwise the bullet's speed depends on your framerate.
Illasera
Illasera
Quote:
Original post by juuso

Replace the BULLET_MOVEMENT_PER_FRAME with some (small) number. That should get you started. But you really should use a velocity for the bullets. Otherwise the bullet's speed depends on your framerate.


Well of course, but first need to know the concept with minimum details to expend for in later use :) , Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.