I've been experimenting with making Guis in Z game editor
and I'd like to make a game in the style of wolvenstein (just for a bit of fun) where the players weapon is visible in front of the camera, but I've been kinda struggling to get this to work.
Basically I want to have a flat object facing the camera on X Y and Z axis,
I've been using this code, which works for z and x axis, but not Y.
Sorry to post this again, I think Kjell might have answered this very same question a few years ago, but I can't find the code.
Code: Select all
float a, s, c, r, x, y;
a = App.CameraRotation.Y*PI*2;
s = sin(a);
c = cos(a);
r = tan(App.FOV/360*PI); // If you're using a constant FOV, you can swap out this calculation with the resulting value.
x = App.MousePosition.X*r*App.ViewportWidth/App.ViewportHeight; // If you're using a constant aspectRatio, you can swap out "App.ViewportWidth/App.ViewportHeight" with a specific value.
y = App.MousePosition.Y*r;
cursor.position.X = App.CameraPosition.X+x*c+s;
cursor.position.Y = App.CameraPosition.Y+y;
cursor.position.Z = App.CameraPosition.Z+x*s-c;
// If you want the box to mimic the orientation of the camera, un-comment the following lines
cursor.rotation.z = 0-App.CameraRotation.z;
cursor.rotation.X = 0-App.CameraRotation.X;
cursor.rotation.Y = 0-App.CameraRotation.Y;