Hello I have a problem and cannot continue.
I have a spaceship. I use a OrbitCam to shoot to the direction where I am looking at with my camera.
The Problem: It’s thirdperson. So the cannons are lower than the camera on the y-axis.
It means the direction alone of camera do not working. So I had new method:
Vector3 offset = transform.InverseTransformPoint(transform.root.position);
RaycastHit hit;
if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 165)) {
Vector3 dir = (hit.point - transform.root.position).normalized;
Targetpos = dir;
} else {
Targetpos = (Camera.main.transform.position + Camera.main.transform.forward*500 - transform.TransformDirection(offset.x, 0, 0)) - transform.position;
}
So this still let me aim to “forward” direction where I am pointing.
The problem is I want to remove Raycast. This “autoaim” isn’t my goal.
The problem is just (if I remove raycast) if a object is far enough maybe I hit him when my crosshair is on him, otherwise my bullets flys under the object because (like I said) my cam is way higher and the cannons (or my ship itself) is lower.
I will show it with pic:
First part of pic is what does work. But next part you see the object is next to me and the direction doesn’t work anymore.
I don’t know how to fix this :(.
