Hello ,i have gone throught tons of other questions and posts but none of them have helped me figure out a solution for my problem. I apologies for the poor terminology but im fairly new to unity .
The set up of this game is 2D , with camera rotation 0,0,0 . I have made a gun object that is pointing with its ,green arrow’’ towards the mouse point. Then i made it shoot/instantiate bullets , and i made the bullets bounce of the walls using the Vector3.reflect , but i can only get the bullets to bounce properly when they are moving ,right ‘’ towards Vector3.right . So whenever i instantiate them they are bouncing the way i wanted but instead of starting off towards the mouse point they move 90 degrees to the side towards the ,red arrow ‘’
So there are 2 things i’ve been trying to do:
Either instantiate the bullets with 90 degrees offset on their Z axis … Or
Edit the reflect angle code to work going , up ‘’ instead of , right ‘’ , but i cant get any of that to work .
Here is the C# scripts that i use for the “gun” object:
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.rotation = Quaternion.LookRotation(Vector3.forward, mousePos - transform.position);
if (Input.GetButtonDown ("Fire1") ) {
Instantiate(Ball, transform.position , transform.rotation) ;}
And this is the script attached to the ball :
transform.Translate (Vector3.right * Time.deltaTime * speed);
Ray ray = new Ray (transform.position, transform.right);
RaycastHit hit;
if (Physics.Raycast (ray, out hit, Time.deltaTime * speed + 0.1f, collisionMask)) {
Vector3 Dir = Vector3.Reflect (ray.direction, hit.normal);
float rot = Mathf.Atan2(Dir.y , Dir.x ) * Mathf.Rad2Deg ;
transform.eulerAngles = new Vector3(0, 0,rot ) ;
I will appreciate any help or advice with this issue as im trying to work it out for the past 4 weeks and its just driving me creazy . Thanks.