Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Bug With 2D Gun

$
0
0
So I have a gun script the follows the mouse and I add force to the right, but in my character controller script if my player moves left it change the scale from 1 to -1 basically changing where the player is looking. So when I move left the gun also faces left but when I shoot the bullet goes right any help? Here is the code: public class ShootGun : MonoBehaviour { public Transform Gun; Vector2 direction; public GameObject Bullet; public float BulletSpeed; public Transform ShootPoint; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); direction = mousePos - (Vector2)Gun.position; FaceMouse(); if (Input.GetMouseButtonDown(0)) { shoot(); } } void FaceMouse() { Gun.transform.right = direction; } void shoot() { GameObject BulletIns = Instantiate(Bullet, ShootPoint.position, ShootPoint.rotation); BulletIns.GetComponent().AddForce(BulletIns.transform.right * BulletSpeed); } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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