Screen Space - Camera makes bullets fly in wrong directions
I'm attempting to use a render texture for my camera, and that is working fine. The problem is however, i need to use the screen space - camera setting on my Canvas to display the UI with the render texture. When i have the canvas set to screen space camera, the bullets fired by my player fly in wrong directions. When i face approx. backwards from the starting point the bullets fly forward, but when i turn the bullets go too much to the right/left in relation to my rotation direction, same with upwards/downwards
This is the bullet instantiation code (it works fine as long as my canvas is in Screen Space Overlay mode):
var bullet : GameObject = Instantiate(bulletPrefab, bulletSpawn.GetComponent.().position, bulletSpawn.GetComponent.().rotation);
Physics.IgnoreCollision(bullet.GetComponent.<Collider>(), player.GetComponent.<Collider>());
bullet.GetComponent.<Rigidbody>().velocity = transform.TransformDirection (bullet.transform.forward * 2);
I'm kinda stumped as to why this is happening, how can the canvas influence how my bullets work? The canvas is rotated and in the right place, so it's not that. If anybody has any alternative ways of drawing a UI on a render texture other than using the screen space overlay method, that'd be great too
Answer by Ozterkvlt · Jun 03, 2017 at 03:20 AM
I fixed it by attaching the bullet fire script to an empty game object in the scene, previously it was attached to the player, also tried the canvas. Strange, maybe a bug?
Your answer
![](https://koobas.hobune.stream/wayback/20220612123401im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Particle rotation problems in Unity 2017.1.0f3 2 Answers
Regarding transform.position in the roll a ball tutorial 0 Answers
Perspective camera touch movement 2 Answers
converto text to texture2D 0 Answers