1
Graphics / Re: How to go about creating a bullet class in SFML 2.0
« on: May 30, 2013, 04:53:53 am »
I agree with MattY's idea; you'd be better served to create a bullet and check for collision with it. You might do something like:
FireMusket(float elapsedTime){
if(elapsedTime >= 2.0f) //or however fast you want to be able to fire
bullet_manager.Add(currentDirection); //currentDirection being the unit vector for your character's facing
}
Then create a bullet class, and a manager container for it (could use a list or map to store bullets). When you call the .Add function like above, you'd multiply the currentDirection vector by the bullet's speed to get the bullets velocity vector. Move the bullet by the vector, and check for collision in each step.
FireMusket(float elapsedTime){
if(elapsedTime >= 2.0f) //or however fast you want to be able to fire
bullet_manager.Add(currentDirection); //currentDirection being the unit vector for your character's facing
}
Then create a bullet class, and a manager container for it (could use a list or map to store bullets). When you call the .Add function like above, you'd multiply the currentDirection vector by the bullet's speed to get the bullets velocity vector. Move the bullet by the vector, and check for collision in each step.