moving entity with mouse()

Blitz3D Forums/Blitz3D Programming/moving entity with mouse()

Ross C(Posted 2003) [#1]
hey, i've got a routine to do this, but it isn't very accurate as the entity seems to shake and jump about, but generally moves in the right direction. I'm using the mouse co-ords for the movement.

Does anyone else have any better ways that work slightly better?


jhocking(Posted 2003) [#2]
It's hard (impossible technically) to say one has a better method without knowing your method. That said, the way I do it (which works reasonably well but is certainly not flawless) is to move the entity with standard movement commands (eg. MoveEntity) based on MouseXSpeed and MouseYSpeed.

To go one better on this I sometimes hide the mouse pointer and have a pointer object in the 3D world which I move with the mouse, using that object as a mouse pointer. This allows me to move entities exactly along with the 3D mouse pointer (whereas the movement in 3D space will not match up exactly with the 2D mouse cursor.)


Ross C(Posted 2003) [#3]
ah, thanks joe. the method i was using was to take the mouse co-ords, subtract half the screen width/height and invert the y. then multiple the values down.

your method sounds interesting tho. i'll give that a shot, thanks for that :)


GIMPY73(Posted 2003) [#4]
any chance of some code for this cos im having probs with mouse routine


Thanks

GIMPY :)


Ross C(Posted 2003) [#5]
well, my way involves keeping the camera locked on the entity, so it moves with the entity. and i move the mouse co-ords back to the centre of the screen.

try this, click the mouse down and hold, then drag the mouse to move the sphere

gw=800
gh=600
Graphics3D gw,gh,16,2
SetBuffer BackBuffer()

x#=0
y#=0

camera=CreateCamera()
PositionEntity camera,0,0,-10

sphere=CreateSphere()


While Not KeyHit(1)
	
	
	
	
	If MouseDown(1) Then
							x=MouseX()
							y=MouseY()
	
							x=(x-(gw/2))*0.01;change 0.01 to alter the speed
							y=(y-(gh/2))*-0.01;change -0.01 to alter the speed. must be minus to flip the axis tho
							PositionEntity sphere,EntityX(sphere)+x,EntityY(sphere)+y,EntityZ(sphere)
							MoveMouse gw/2,gh/2
	End If
	
	UpdateWorld
	RenderWorld
	Flip
Wend
End



GIMPY73(Posted 2003) [#6]
thanks joker ill try ur code i also lock the camera onto the entity at a 45 degree angle (isometric style)
i use camera picked to select the terrain but im trying to get my entity to rotate left and right with the mouse also move in the direction the mouse is going


Thanks
GIMPY:)


Ross C(Posted 2003) [#7]
ah, that's the same thing i'm doing. i have it mostly all working. i could e-mail you it if you want?


GIMPY73(Posted 2003) [#8]
Sorry for not replying sooner lol but try this joker

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

Oh and if any of u code wizards can improve this pls post it back in this thread

Thanks

GIMPY :)


Ross C(Posted 2003) [#9]
hey, that's nice! what i'm using my camera system for is an animation studio, purely using pivots, so the animations can be applied to mulitple charaters in the game. so i'm using the camera pick for selecting pivots, parenting them, rotating them all using the mouse's on-screen position.

sorry for boring you with that, but you code looks cool :)