- Home /
Shooting Realistic Bullets
I am trying to make a completely realistic FPS game. I want to control the exact speed the bullet comes out at. But when I use Time.deltaTime and the correct Meters per second number, it only shoots the bullet about a meter in front of the person.
var MPS : int = 137;
var BB : Rigidbody;
var automaticWeapon : boolean = false;
var semiAutoWeapon : boolean = true;
var lastShot;
var shotInterval : float = .1f;
var deleteBulletTime = 4.5;
function Update ()
{
if(semiAutoWeapon == true)
{
if(Input.GetButtonDown('Fire1'))
{
var instantiatedBB : Rigidbody = Instantiate(BB, transform.position, transform.rotation);
instantiatedBB.velocity = transform.TransformDirection(Vector3( 0, 0, MPS * Time.deltaTime ));
Physics.IgnoreCollision( instantiatedBB. collider, transform.root.collider );
}
}
}
PS: can someone tell me how to make my script look right in my post? Thanks
there is a code button that looks like 010101. Select all your code and press the button.
Please don't throw around terms like "completely realistic" so casually. Even highly experienced programmers and artists have trouble trying to achieve that standard.
Answer by Marnix · Jun 23, 2011 at 10:08 PM
You don't need to multiply it with deltaTime. This is only when you will actually do an update method of the bullet. So, change its position manually.
If you just want to set the velocity, use only the speed/second value.
deltaTime is the difference between two frames, so it differs per frame. It has values like 0.002.
Answer by oliver-jones · Jun 23, 2011 at 10:22 PM
You want to use something like this on your bullet:
var bulletSpeed : float = 100;
function FireBullet(){
var velocity = rigidbody.velocity;
velocity = moveDirection.normalized*bulletSpeed;
}
Hope that helps a little
Your answer
Follow this Question
Related Questions
colliding bullets 2 Answers
spraying bullets 3 Answers
fps shooting enemy 1 Answer
Sniper bullets not working 0 Answers
bullets flying through enemy 1 Answer