- Home /
An opinion on a bullet code
The following code is attached to a bullet which is a rigidbody.
static var speed; private var coeff; private var dragvalue; private var alpha; private var bullarea; private var secden; private var balcoeff; private var masses;
function Start() { speed = 868; coeff = 0.1; dragvalue = 2; alpha = 1.1839; bullarea = 1.086; secden = 0.16; balcoeff = 0.17; masses = 0.535;
}
function Update () { if ((speed > 1544)&&(speed<=1699)) coeff = 0.09; if ((speed > 1390)&&(speed<=1544)) coeff = 0.103; if ((speed > 1235)&&(speed<=1390)) coeff = 0.109; if ((speed > 1081)&&(speed<=1235)) coeff = 0.12; if ((speed > 926)&&(speed<=1081)) coeff = 0.135; if ((speed > 772)&&(speed<=926)) coeff = 0.15; if ((speed > 618)&&(speed<=772)) coeff = 0.165; if ((speed > 463)&&(speed<=618)) coeff = 0.19; if ((speed > 309)&&(speed<=463)) coeff = 0.21; if ((speed > 154)&&(speed<=309)) coeff = 0.07; if ((speed > 0)&&(speed<=154)) coeff = 0.06; if (speed <= 0) coeff = 0;
dragvalue = 0.5 * alpha * (speed*speed) * bullarea * (coeff*(secden/balcoeff));
var newval = dragvalue/masses;
speed = speed - (newval * Time.deltaTime);
velocity = transform.TransformDirection( Vector3(10, 0, speed ) );
}
When fired however i dont believe this is actually adjusting the velocity of the projectile. Could anyone give their opinions on this matter?
Answer by runevision · Feb 24, 2011 at 05:04 PM
To adjust the rigidbody velocity, you need to adjust
rigidbody.velocity
instead of just
velocity
This assumes that the Rigidbody is attached to the same GameObject as the script.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110043im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
sending message to bullet (javascript) 1 Answer
help with bullet shooting code? - javascript 1 Answer
On TriggerEnter issues 1 Answer
Question About Bullet Decals Javascript 1 Answer
Bullets will not fire forwards 1 Answer