Moving an entity with the mouse?

Blitz3D Forums/Blitz3D Programming/Moving an entity with the mouse?

CopperCircle(Posted 2005) [#1]
Hi, I want to be able to move an entity forward, back, left & right with the mouse, the problem im having is coming up with a good function to compensate for a change in the camera angle.

The code bellow shows the problem, if you rotate the camera(right mouse) and move the object(left mouse) the mouse movements obviously have to alter with the angle.

Any help would be great.




DJWoodgate(Posted 2005) [#2]
Maybe...
TFormVector MouseXSpeed()/5.0,0,-MouseYSpeed()/5.0,campiv,0
TranslateEntity cube,TFormedX(),0,TFormedZ()

or ...

TFormVector MouseXSpeed()/5.0,0,-MouseYSpeed()/5.0,campiv,cube
MoveEntity cube,TFormedX(),TformedY(),TFormedZ()

Edit... I have added tformedy() back into the second one, just in case you decide to start rotating the cube.

Something to bear in mind is using moveentity the movement will be scaled by the entity scale. Not so bad perhaps and maybe what you are after, but if the entity is not uniformly scaled it is going to go every which way, so you will have to scale your movement accordingly. i.e.
TFormVector MouseXSpeed(),0,-MouseYSpeed(),campiv,cube
MoveEntity cube,TFormedX()*xscale*0.2,TFormedY()*yscale*0.2,TFormedZ()*zscale*0.2

The first option using translateentity avoids this issue.


Rob Farley(Posted 2005) [#3]
Easy solution.

guide = createpivot()

repeat

positionentity guide,0,0,0
rotateentity guide,0,entityyaw(camera),0
moveentity guide,mousexspeed(),0,mouseyspeed()

moveentity thingy,entityx(guide),0,entityz(guide)

until keyhit(1)

Anyway... totally untested but you get the idea.


CopperCircle(Posted 2005) [#4]
Thanks guys.


Rook Zimbabwe(Posted 2005) [#5]
It always seems to be a pivot. I have the same prob! : )
-RZ