Quantcast
Channel: Latest Questions by orcinusdev
Viewing all articles
Browse latest Browse all 26

C# Simple turret script problem

$
0
0
Hello! I have the simplest Turret code which doesn't work. It fires projectiles in Z direction (?!) When player is at the positive x positin of the turret the turret shoots upwards in Z, otherwise downwards. It is always facing the player however. What is wrong? I attached this code to a simple cube. And the target is a moving player. using UnityEngine; using System.Collections; public class TurretScript : MonoBehaviour { public GameObject projectile; public Transform target; void Start(){ RepeatShooting(); } void Update(){ transform.rotation = Quaternion.LookRotation (target.position - transform.position); } // Shoot and repeat void RepeatShooting () { InvokeRepeating ("LaunchProjectile", 2, 0.3f); } public void LaunchProjectile(){ //Vector3 projectileStart = new Vector3( Instantiate (projectile, transform.position, transform.rotation); } }

Viewing all articles
Browse latest Browse all 26

Latest Images

Trending Articles





Latest Images

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