I'm trying to fire a bullet toward the mouse but if I fire then it goes to the wrong direction what should I do? and the offset I set is 90 Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class weapon : MonoBehaviour { public GameObject projectile; public Transform shotposition; private float Timebtwshots; public float starttime; public float offset; void Start() { } // Update is called once per frame void Update() { Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; float rotz = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rotz + offset); if (Timebtwshots <= 0) { if (Input.GetMouseButtonDown(0)) { Instantiate(projectile, shotposition.position, transform.rotation); Timebtwshots = starttime; } }else { Timebtwshots -= Time.deltaTime; } } } this is the code for my weapon Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class projectile : MonoBehaviour { public float speed; public float lifetime; void Start() { Invoke("DestroyProjectile",lifetime); } // Update is called once per frame void Update() { transform.Translate(transform.up* speed *Time.deltaTime); } void DestroyProjectile() { Destroy(gameObject); } } and this is the code for my bullet
sorry I forgot to change transform.Translate(transform.up* speed *Time.deltaTime); in to transform.Translate(Vertor2.up* speed *Time.deltaTime);