Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Orbit around an object in all 3 dimensions? Can only get 2 to work properly

Omega gamer 89
Years of Service
User Offline
Joined: 10th Sep 2007
Location: Pittsburgh, PA
Posted: 20th Sep 2020 13:32
So basically, I have it set up that the player moves around with the WASD keys, and the camera is moved around with the mouse. What Im trying to do now is get it so that a specific object is positioned in front of the player, at an opposite angle from the camera. To explain a bit better, imagine if you had a pole going from the camera positioned behind the player, through the player's body, and ending at a point in front of the player, always directly front and center where the camera is pointing.

Ive got the positioning on the X and Z working, but for the absolute life of me I cannot get the Y positioning to work properly. They way it SHOULD work is that, as you pan up, the object should move up on the Y axis, but also move closer to the player on the X and Z axes so that it maintains a constant distance from the player. Basically, it moves in a sort of dome shape around the player. But I cant figure out how to DO that! I have make it move up and down when you pan up and down, but I cant figure out how to ALSO move it on the X and Z by an equivalent amount so it maintains a constant distance.

Right now, the object only moves STRAIGHT up and down on the Y axis, rather than following a curve and moving around a dome-shape around the player.

Here is the code im using

Im sure theres probably some super obvious solution using ATAN or some such, but to be perfectly honest Im horrible at math, and I dont even know what tan and cos and sin and all that even are or what they do, so I have no idea what would be needed to make this work.

Any help greatly appreciated.
Years of Service
User Offline
Joined: 5th Mar 2007
Posted: 26th Sep 2020 19:26
Maybe have an invisible sphere surrounding the player, with the object as a visible limb
DBPro Master
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 13th Oct 2020 06:07
get the vector from camera position to player, then double it and you have your desired point

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.

Login to post a reply

Server time is: 2023-11-28 22:25:51
Your offset time is: 2023-11-28 22:25:51