- Home /
Question by
songhoseok2 · Feb 26, 2017 at 01:01 PM ·
movementgameobjectshootingtranslateshoot
How do you make bullets face the direction it's going?
After it's spawned, it moves finely but after it hits something, the direction the bullet is facing and the direction of its actual travel starts to differ and the bullet flies in a circle wildly. Also the bullet rotates around while traveling, which isn't what I want (I want it to travel in a straight line). Is there any way to fix this? here's my script:
using UnityEngine;
using System.Collections;
public class BulletMovement : MonoBehaviour
{
public float moveSpeed;
public float bulletLasts;
float destroyTime = Time.time;
// Use this for initialization
void Start()
{
destroyTime = Time.time + bulletLasts;
}
void Update()
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
//GetComponent<Rigidbody>().velocity = transform.forward * moveSpeed;
//GetComponent<Rigidbody>().AddForce(transform.forward * moveSpeed);
`
if (Time.time >= destroyTime)
{
Destroy(gameObject);
}
}
}
I attempted many ways to make the bullet travel, but none of them fix the problem. Would anyone please help me?
Comment
FYI, this started to happen after I added the capsule collider to the bullet (the bullet is just a small capsule 3D object)