moving objects 'away'/'toward' camera

Blitz3D Forums/Blitz3D Beginners Area/moving objects 'away'/'toward' camera

ryan scott(Posted 2005) [#1]
i have a camera that moves around independently of the player's ship.

i am wondering how i can make it so that when the player presses the UP key, the ship moves 'away' from the camera, how do i translate to the X,Z that i need to move the ship?

the ship doesn't always face 'forward', so i can't just add to Z. the ship faces various directions independently of the direction you push, so i'm moving the pivot x,z along the terrain plane.

if the camera first starts out, the up arrow moving 0,Z+1 works fine. But if the camera moves 90 degrees to the side but is still pointing at the ship, then UP means X+1,0

and so on, for all the possible angles.

how then to get the correct X,Z for the ship based on where the camera is?


Grey Alien(Posted 2005) [#2]
Are you making a 3D app in Blitz plus?


Beaker(Posted 2005) [#3]
Ryan - this is the 4th post of yours in the last week or two I have had to move to the correct forum!


Stevie G(Posted 2005) [#4]
Something like this should work ....

Dx# = ( keydown( 203) - keydown(205) ) * speed#
Dz# = ( keydown( 200) - keydown(208) ) * Speed#
tformvector Dx,0,Dz, CAMERA, 0
translateentity SHIP , tformedx() , 0 ,  tformedz()


Cheers
Stevie


ryan scott(Posted 2005) [#5]
thanks beaker

i'm sorry i might have had multiple windows open to blitzbasic.com and posted one window after i had switched forums in another. :/ I was researching while composing the post. I'll have to make sure i don't do that.

thanks Stevie G!

this definitely seems to move the ship in the right direction, but at inconsistent speeds. depending on the rotation of the camera, the ship moves much more quickly left/right, or if you rotate the cam a little, forward/back. about 5* faster

is there a way to compensate? it seems that * speed doesn't translate right here. I want it to move * speed on the ground, and it seems that * speed here causes tformedx()/z() to be far more and far less than speed.

example output printing them:

t_x() t_z()
going away:
0.0 -1.74218
going left
-10.0 0

so it zooms left and right, crawls forward and back. :?

even when the cam is directly above the ship it doesn't behave consistently on the different axes.

hmm i have no ideas here, any clues?


Baystep Productions(Posted 2005) [#6]
Really, I'd just get the yaw and pitch of the camera, match it to the ship using some rotational tweaning like in the smart camera, or the tracking functions, so that the ship in the end has the rotational values as the camera, then just moveentity on it.

RotateEntity ship,EntityPitch(camera),EntityYaw(camera),0
MoveEntity ship,0,0,1



Stevie G(Posted 2005) [#7]
Do you scaleentity the camera at all? This will also scale tformvector results. Try tformnormal ...

Dx# = ( keydown( 203) - keydown(205) )
Dz# = ( keydown( 200) - keydown(208) )
tformnormal Dx,0,Dz, CAMERA, 0
translateentity SHIP , tformedx()*speed , 0 , tformedz()*speed


ryan scott(Posted 2005) [#8]
Stevie G

i don't scale the cam.

the code you provided returns value for x,y and z. Not just x and z.

I think maybe i'm not clear on the setup. The camera is way above, and slightly behind the ship. but you can move it anywhere in relation to the ship, to the side, whatever. The terrain slopes off into the distance. ship sits flat on it. to move ship left, i moveentity ship,-speed,0,0. to move up/forward/away, whatever you want to call it, moveentity ship,0,0,speed. ship does not face where it moves, so i don't rotate and move forward.

When the player presses up, it should move the car what appears to be 'away' (if the car were facing that direction it would drive 'forward'). i need to get an x and z as far as the car is concerned. doing anything to car's Y makes it float up or sink down into the terrain.

That Y component is taking away from x and z.

i'm perplexed. there is no example of this anywhere i can find.

i tried translating from screen to the terrain the ship is on, that produces the same answers (car is aligned to that terrain anyway so it should)

if you put a piece of paper on the screen, and drew a line from the ship straight up, when player presses UP and the ship moves, it should be moving a combination of x and z that follows that line. of course you're looking at a terrain on the y plane so it would move the car along that terrain.

does this make sense?


ryan scott(Posted 2005) [#9]
hmm doesn't the camera's Y translate to up and down on your screen? not z... ? z means in and out or forward/back. if you move camera by -Y it moves up your screen.

so i think this is doing what i want.

x# = ( keydown( 203) - keydown(205) ) 
z# = ( keydown( 200) - keydown(208) ) 
If x Or z  ; if you don't do this then tformedy, etc is NaN so we get bad values
TFormVector x,z,0, cam, carpiv ; note the position of Z!!
; now convert the x and z components into a normal.  we don't want the Y part.  x and z too small because Y takes away from the 1
TFormNormal TFormedX(),0,TFormedZ(),carpiv,carpiv  ; zero out y and get a normal. yes carpiv to carpiv
MoveEntity carpiv , TFormedX()*carspeed , 0 , TFormedZ()*carspeed 
							
DebugLog TFormedX()+" "+TFormedY()+" "+TFormedZ() 
EndIf


now i occasionally get Y values but they appear to be due to floating point precision errors and are very tiny.

this appears to work no matter position of cam. at least so far.