- Home /
Shoot Projectile
I'm making a FPS and need a projectile to be shot along the raycast, not sure how to do it. THANKS IN ADVANCE, here's my code that shoots the raycast :
if(Input.GetMouseButtonDown(0)&& ammo > 0){
animation.Play("m14_shoot");
arm.animation.Play("am14_shoot");
ammo -= 1;
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, fwd, 460)) {
print ("Hit!");
}
else{
print("Nothing!");
}
Debug.DrawRay(transform.position, transform.forward * 460, Color.green);
}
Any object moving as fast as an actual bullet - or even a tenth of that speed for that matter - will be practically invisible to the eye. If I understand what you actually want, the ubiquitous Whizzing Bullet effect in many games is usually a line with some kind of "spark" texture, and generally only appears for a tenth of a second at some point along the raycast's path. Start with a LineRenderer component, as it's the easiest way to get a prototype up and running.
You can also use a jazzed-up Particle System aligned with the weapon's muzzle and have it Emit(1) every time you fire. I assume you use the Raycasts to resolve the bullet's collision, yes?
Your answer
Follow this Question
Related Questions
How do I make a gun project a particle? 1 Answer
FPS PISTOL 1 Answer
Raycast hitting below mouse position :( 0 Answers
Raycast Positioning 2 Answers
Where can i find an easy raycast shooting tutorial for C#? 2 Answers