Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Shooting a Bullet with AI in Unity

$
0
0
Well as I am making a First Person Shooting game, however the bullet shooting from the enemy seems to spray shoot upwards and I can't do anything about it at all as I don't know how Unity works, so here below is the script: function Update () { if(LookAtTarget) { var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp); var seconds : int = Time.time; var oddeven = (seconds % 2); if (oddeven) { Shoot(seconds); } } } function Shoot(seconds) { if (seconds!=savedTime); { var bullit = Instantiate(bullitPrefab ,transform.Find("Spawn2").transform.position , Quaternion.identity); bullit.gameObject.tag = "enemyprojectile"; bullit.rigidbody.AddForce(transform.forward * 1000); savedTime=seconds; } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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