Limiting the crosshair

Blitz3D Forums/Blitz3D Programming/Limiting the crosshair

Mortiis(Posted 2007) [#1]
Well I'm working on a 3d shooter, in my game the crosshair is independent from the player spaceship and it's mouse controlled so as it's the mouse icon you can move it anywhere on screen.

The problem is, the crosshair is a quad in 3d space which has a pivot, controlled with mousexspeed and mouseyspeed and it's also parented to spaceship so when the spaceship moves it moves too as it's 2d.

I can't limit it's movement by viewport limits and it goes out of sight.Any ideas to limit it's movement by screen edges? Thanks!


b32(Posted 2007) [#2]
I'm not sure if this would be the best way. The idea is that if you parent the crosshair to the camera, it should allways have coordinates that are relative to the camera.
Then, on initializing your program, you could create a temp. Plane, move it at the same z-distance from the camera as the crosshair, set it's picking mode to 2 and use CameraPick to pick the 3d coordinates in each corner of the screen.
At runtime, you could use these the x and y of these 3d coordinates to limit the crosshairs movement.


Mortiis(Posted 2007) [#3]
Thanks b32 I'll keep it in my mind, anyone else with a more practical idea?


b32(Posted 2007) [#4]
:) funny ..


However, instead of using MouseXSpeed/MouseYSpeed, you could also create the plane, make it invisible using EntityAlpha and pickable, and use CameraPick to determine where the crosshair should be:



Stevie G(Posted 2007) [#5]
Something like this?

[EDIT] Brams solution is better.


Graphics3D 800,600,16,1

camera = CreateCamera()
cursor = CreateCube( camera ) : ScaleMesh cursor, 1,1,.1

While Not KeyDown(1)

	x# = LIMIT( EntityX( cursor ) + MouseXSpeed()*.01 , -10.0 , 10.0 )
	y# = LIMIT( EntityY( cursor ) - MouseYSpeed()*.01 , -7.5, 7.5 )
	MoveMouse 400,300
	PositionEntity cursor, x, y, 10

	RenderWorld()
	Flip
	
Wend


Function  LIMIT# ( q#, lo#, hi# )

	If q < lo q = lo
	If q > hi q = hi
	Return q
	
End Function



Mortiis(Posted 2007) [#6]
@b32:Thank you so much! I thought it was harder to code what you mentioned that's why I asked for something more practical but it's the easiest way.Thanks...

@Stevie G:Thanks, I'll stick with b32's anyway.Thank you...


Mortiis(Posted 2007) [#7]
One more problem, in the game there are some objects like asteroids pickable for AI to evade them while chasing the player.

When crosshair moves on those pickable objects, it changes the Y position and moves closer to the top-down camera. It looks bad and the launched rockets and fired weapons move to false coordinates.


Gillissie(Posted 2007) [#8]
Don't use PickedY() to set your crosshair position if you already know what it is going to be. Just hard-coded it to the same height as your ship, or just above the ground.