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
sync on : Sync rate 0
autocam off : hide mouse
`Make a "player" object
make object cube 1,5
`Make an object to move around in front of us
make object sphere 2,1
`This object is basically for the camera to attach itself to. I tried just moving the camera directly rather than moving this object
`and then moving the camera around that, and it just... wouldnt run. It would compile, but then not do anything.
`Either way, this part isnt the problem
make object sphere 3,1
ghost object on 3
make matrix 1,1000,1000,50,50
do
MMx = Mousemovex() : MMy = Mousemovey()
X# = WrapValue(X# + MMx)
Y# = WrapValue(Y# + MMy)
`Rotate the player based on mouse movement
yrotate object 1,X#
`position that camera-pivot object at the players position, then move it up and back a bit.
position object 3,object position X(1),object position y(1),Object position Z(1)
move object 3,-10 `when I tried doing this by positioning the camera itself at the player position, and then
move object up 3,10 `just doing "move camera" and "move camera up" instead of using an object as a middle man, the
Yrotate object 3,Object angle y(1) `program just wouldnt DO anything. Itd complile file, but itd never open an actual application. I have no idea why
`position the camera
position camera object position X(3),object position y(3),Object position Z(3)
`rotate the camera based on mouse movement
yrotate camera X#
xrotate camera Y#
`use WASD keys to control player movement
if keystate(17) then move object 1,0.02
if keystate(31) then move object 1,-0.02
if keystate(30) then move object left 1,0.02
if keystate(32) then move object right 1,0.02
`Ok, so THIS is the part thats giving me trouble. as-is, the X ad Z work great, but I cant figure out how to get them to work
`TOGETHER with the Y. If you run the code, youll see the small sphere moves up and down on a straight line, rather than moving
`closer to the player on the X and Z as it moves up the Y, so as to maintain a constant total distance from the player.
`I have spent DAYS and tried a million different things, and I cant figure it out. In my defense, Im really not good with math
`and I honestly dont even truly actually KNOW what sine and cosine and all that even ARE. I managed to piece this together from
`code snippets and examples, so I dont know how to take it the next step further and integrate the Y with the X and Z.
position object 2,object position x(1) + sin(X#) * 30, sin(-Y#) * 30,object position z(1) + cos(X#) * 30
sync
loop
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.