Quantcast
Viewing all articles
Browse latest Browse all 1488

My bullet has no velocity after it is spawned.

I can instantiate my bullet but no code i put after it will give it a velocity. Addforce and transform won't work. I keep getting errors maybe because I'm using Unity 5. Please help me. I can post the whole code if requested but I'm pretty sure all I need is this last line. Also I'm not getting an error as technically the prefab is spawned it just doesn't have any velocity. The prefab for the bullet has a simple destroy gameobject when it collides script. using UnityEngine; using System.Collections; public class EnemyAIScript : MonoBehaviour { public Transform player; public float playerDistance; public float rotationDamping; public float chaseStartRange; public float moveSpeed; public static bool isPlayerAlive = true; public float fireRate; public float maxFire; public float nextFire; public GameObject BulletPrefab; public float BulletSpeed; void Update () { Vector3 direction = transform.position; if (isPlayerAlive) { playerDistance = Vector3.Distance (player.position, transform.position); if (playerDistance < 20f) { lookAtPlayer (); } if (playerDistance < 20f) { if (playerDistance > 8f) { chase (); } else if (playerDistance < 8f) { attack (); } } } } void lookAtPlayer () { Quaternion rotation = Quaternion.LookRotation (player.position - transform.position); transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * rotationDamping); } void chase () { transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime); } void attack () { if (Time.time > nextFire) { nextFire = Time.time + fireRate; Instantiate (BulletPrefab, GameObject.Find ("spawnPoint").transform.position, Quaternion.identity); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>