Shooting projectiles with FPS controller
All I want to do is fire a projectile in the direction I am looking. I am using the FPS-Controller and my projectile is just a basic sphere.
I know I probably messed something basic up, but this is what I have:
void Update () {
if (Input.GetMouseButtonDown(1))
{
Vector3 transformation = character.transform.forward;
GameObject g = Instantiate(basicShot,character.transform.position+ trans * 5, character.transform.rotation) as GameObject;
g.GetComponent<Rigidbody>().AddForce(trans * 100);
g.GetComponent<Rigidbody>().useGravity = false;
}
character is the Rigidbody from the FPS Controller
Currently the projectile fires in the correct detection on the x-z plane, but does not have any y velocity (neg or pos) no matter how i rotate the camera
The force you're applying is probably just too low because this happens at only one frame, use:
AddForce(trans * 100, Force$$anonymous$$ode.Impulse);
Also make sure that the 'trans' variable is character.transform.forward. In your script you had a different name on it for some reason.
Answer by sunshine_boy · Sep 26, 2016 at 01:05 PM
cause the transfom.forward you used was not the camera's
Answer by SohailBukhari · Sep 26, 2016 at 12:16 PM
@username Use Velocity Instead Of Adding Force
Rigidbody rb = Instantiate(projectile,origin.position, origin.transform.rotation) as Rigidbody; rb.GetComponent().velocity = rb.transform.forward Time.deltaTime shotForce;
Your answer
