Entity cursor following
Blitz3D Forums/Blitz3D Programming/Entity cursor following
| ||
I've got this idea - which I'm sure wont work anyway, but here's the pitch. I'm working on an ISO game, that doesnt have a fixed camera - instead you can zoom round and in & out. (bit like the insidey bits of commando 2) Thats all sorted, but I want to control my main character by pointing the way with the mouse on screen. I cant use some of these fancy 2d projection functions that already exist, cos the camera and axis wont be fixed. My idea is to find the 2d coords of the object, compare them with the mouse coords. With that info, hopefully find the amount of rotation required around the Y axis of my character to point it in the right direction. Doesnt matter where the Z or X of entity are, just as long as I can rotate to the same direction as to where the mouse is pointing. I've got the 2d coords of my entity, and the mouse coords. But I think I need some 'TRIG' to work out the angle of one to the other to give me a rotation value. (dont want to use pivots, rather keep it maths based as the camera moves about too much) Any advice/help please Guys ! Thanks. |
| ||
Have a look at the ATan2 function in the online docs. I think this maybe what you're after. |
| ||
The easiest way, would be to use a pivot, use camerapick to click on the ground, and then just have the guy pointentity to the pivot. |
| ||
I would also know how to do this i tried the pivot method and the camera just spins around the block realy fast :) so any ideas??? Thanks GIMPY :) |
| ||
Try this PaulJG u will need a bitmap for the ground Graphics3D 800,600,16,1 SetBuffer BackBuffer() light=CreateLight() Collisions 3,2,2,2 Global pointer = CreateSphere() ScaleEntity pointer,.5,.5,.5 EntityColor pointer,0,256,0 EntityType pointer,2 Global cube=CreateCube() EntityRadius cube,2,2 EntityType cube,3 Global cam=CreateCamera(pointer) CameraRange cam,.1,1000 TurnEntity cam,0,0,0 RotateEntity cam,45,0,0 EntityType cam,2 PositionEntity cam,0,80,-80 pl=CreatePlane() tex=LoadTexture("grass3.bmp") ScaleTexture tex,64,64 EntityTexture pl,tex EntityOrder pl,1 EntityFX pl,1 EntityType pl,1 EntityPickMode pl,2 ScaleEntity pl,1,1,1 While Not KeyDown(1) If MouseDown(1)=True picked=CameraPick(cam,MouseX(),MouseY()) PositionEntity pointer,PickedX(),0,PickedZ() MoveEntity cube,0,0,pz+1 EndIf movebloke() UpdateWorld RenderWorld Flip Wend End Function movebloke() mx#=MouseXSpeed()*0.2 my#=-MouseYSpeed()*0.2 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 MoveEntity pointer,mx,0,my PointEntity cube,pointer End Function Thanks GIMPY ;) |
| ||
Thanks Gimpy, I sorta got there in the end - but my solution is somewhat different to yours.. (based on the guys recommendations above) :) When you use the pointentity command it points all directions to the curor position, (which is no good when my man was jumping, he would face the ground) - so I got around it, by calculating the angle between the object and the cursor using ATAN2 and then physically rotating the object around the Y. That way I can keep the X and Z the same. :) |
| ||
Nice 1 PaulJG glad u got it sorted :) i think ill have a play about with the ATAN2 function cos i noticed wot u just said about the entity pointing down when it jumps up Thanks GIMPY :) |
| ||
an on a mo.. I'll post up some of my code |
| ||
CameraPick(camera,MouseX(),MouseY()) PositionEntity cameramarkerpivot,PickedX#(),PickedY#(),PickedZ#() x1#=PickedX#()-EntityX(manpivot) y1#=PickedZ#()-EntityZ(manpivot) ang=(180+(ATan2(y1#,x1#))) PositionEntity cursormarker,PickedX#(),PickedY#(),PickedZ#() RotateEntity manpivot,0,ang,0 Maybe that'll help. ;) |
| ||
Thanks m8 ill give it a try:) Thanks GIMPY :) |