bullet wont move forward
i have this script:
var projectile : Rigidbody;
var speed = 1;
var barrel : Transform;
var shots : int = 0 ;
var maxShots : int = 1 ;
var fwd : Vector3;
function Update () {
fwd = transform.TransformDirection(Vector3.forward);
if ( Input.GetButtonDown ("Fire1") && shots < maxShots){
var bullet1 : Rigidbody;
bullet1 = Instantiate(projectile, barrel.position, barrel.rotation) as Rigidbody;
bullet1.GetComponent(Rigidbody).useGravity = false;
bullet1.GetComponent(Rigidbody).AddForce(fwd * speed, ForceMode.Impulse);
shots ++;
}
else if (shots >= maxShots && Input.GetKeyDown(KeyCode.R))
{
Reload();
}
}
function Reload() {
yield WaitForSeconds(0.5);
shots = 0;
}
it' s not 100% mine i used some parts of a tutorial but when i add the force my bullet will just float in the air where it is spawned can someone tell me whats wrong cause i honestly thing it should work but it' s probably something small
Answer by yvyv1000 · Oct 21, 2015 at 09:22 AM
i fixed my problem that kanematic shouldn' t be on but off so i changed and now it works its strange though cause unity actually can't do without it if you have mesh collider on so i changed it to sphere
changed it again ins$$anonymous$$d of the var fwd i now use transform.forward but still floating in the are doing nothing
Answer by smallbit · Oct 21, 2015 at 04:48 AM
You are adding force of 1, If you didn't change the mass of rigidbody (which is 1 by default) you are adding way to small force to it. Try bigger values for your speed, and see what happens or alternatively decrease the mass of the bullet.
Also you can remove the code from update, there is no need to run it every frame.
i already changed the speed value in the editor to 100 still no change
also it needs to be in update in order to shoot after it cause as you can see the shoot is triggered when i press the "Fire1" button so if i put it in start i can' t use it anymore i tryed but then the bullet won' t even appear
i need to add that my projectile is not using gravity and it is kanematic
Your answer
Follow this Question
Related Questions
Trying to work with Addforce to move my character 1 Answer
Change direction of rigidbody when force is no longer being applied 2 Answers
AddForce in Character Controller problem 0 Answers
Why can't I get ball movement with this script? 1 Answer
How does one continuously move an object forward without using velocity? 1 Answer