This code works, I need to generate the "blood sphere" at the location of the picked sphere but I can only seem to pick the environment.
Graphics3D 800,600,32,1
Dither True
AntiAlias True
BackBuffer()
Type enemy
Field X
Field Y
Field Z
Field shape
End Type
Global pistolselected=0
Global Gravity# = -.5
Global WalkSpeed#=.5
Global FlyMode=0
Global weaponout=0
Global pistolammo=15
Global CamPivot = CreatePivot( )
Global Camera = CreateCamera( )
PositionEntity CamPivot,1010,50,1010
EntityType CamPivot, 1
EntityRadius CamPivot, 3
EntityType Camera, 1
EntityRadius Camera, 2
Global pistol=CreateCylinder()
EntityParent pistol,camera
PositionEntity pistol,EntityX(Camera)+1.5,EntityY(Camera)-2,EntityZ(Camera)+2
RotateEntity pistol,100,0,0
HideEntity pistol
Global muzzleglow2=CreateLight(pistol)
LightRange muzzleglow2,.0005
HideEntity muzzleglow2
LightColor muzzleglow2,255,255,0
Global t=0
Collisions 1,2,2,3
Function Loadlevel1()
light=CreateLight(2)
PositionEntity light,600,100,600
RotateEntity light,90,0,0
LightColor light,100,255,255
terrain=CreateTerrain(32)
PositionEntity terrain,0,-.02,0
ScaleEntity terrain,50,20,50
EntityType terrain,2
EntityPickMode terrain,2
city1=CreateCube()
PositionEntity city1,1000,1.5,1000
EntityType city1,2
EntityPickMode city1,2
ScaleEntity city1,50,20,50
enemies=0
SeedRnd 4
Repeat
e.enemy=New enemy
e\x=Rnd(1,1000)
e\y=4
e\z=Rnd(1,1000)
e\shape=CreateSphere()
PositionEntity e\shape,e\x,e\y,e\z
ScaleEntity e\shape,4,4,4
EntityType e\shape,3
EntityPickMode e\shape,3
enemies=enemies+1
Until enemies=10
CameraRange Camera,.2,1000
CameraFogMode Camera,1
CameraFogRange Camera,.2,999
CameraFogColor Camera,19,164,149
CameraClsColor Camera,0,255,255
While Not KeyHit(1)
controls()
Wend
Return
End Function
Function controls()
Color 255,0,0
If pistolselected=1
WritePixel 355,255,0
EndIf
If KeyDown( 42 ) =1
WalkSpeed# = 1.5
Else
WalkSpeed# = .5
EndIf
If KeyHit(2)
ShowEntity pistol
pistolselected=1
weaponout=1
End If
If FlyMode=0
If KeyDown(17) =1 Then MoveEntity CamPivot, 0, 0, WalkSpeed#
If KeyDown(31) =1 Then MoveEntity CamPivot, 0, 0, 0-WalkSpeed#
PositionEntity Camera, EntityX#( CamPivot ), EntityY#( CamPivot )+8, EntityZ#( CamPivot )
EndIf
If KeyDown(30) =1 Then MoveEntity CamPivot, -1, 0, 0
If KeyDown(32) =1 Then MoveEntity CamPivot, 1, 0, 0
If EntityCollided(CamPivot,2)
Gravity#=0
Else
Gravity#=-.5
EndIf
TranslateEntity CamPivot, 0, Gravity#, 0
TurnEntity CamPivot, 0, 0 -MouseXSpeed(), 0
TurnEntity Camera, MouseYSpeed(), 0, 0
RotateEntity CamPivot, EntityPitch#( CamPivot ), EntityYaw#( CamPivot ), 0
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
RotateEntity Camera, EntityPitch#( Camera ), EntityYaw#( CamPivot ), 0
If MouseHit(1)And pistolselected=1 And pistolammo>0
createbullet()
pistolammo=pistolammo-1
EndIf
If t=1
Text 0,20,"Enviroment picked"
EndIf
Text 0,40,"Press 1 to pull out pistol, aim with the dot"
Flip
UpdateWorld()
RenderWorld
HideEntity muzzleglow2
Return
ClearCollisions
End Function
Function createbullet( )
If pistolselected=1
ShowEntity muzzleglow2
EndIf
If weaponout=1
picked=CameraPick(camera,378,278)
If picked>1 Then
t=1
EndIf
If picked<2
blood=CreateSphere()
ShowEntity blood
EntityShininess blood,1
EntityColor blood,200,0,0
ScaleEntity blood,1,1,1
PositionEntity blood,PickedX(),PickedY(),PickedZ()
EntityType blood,1
EndIf
EndIf
End Function
Graphics3D 800,600,32,1
Dither True
AntiAlias True
BackBuffer()
Type enemy
Field X
Field Y
Field Z
Field shape
End Type
Global pistolselected=0
Global Gravity# = -.5
Global WalkSpeed#=.5
Global FlyMode=0
Global weaponout=0
Global pistolammo=15
Global CamPivot = CreatePivot( )
Global Camera = CreateCamera( )
PositionEntity CamPivot,1010,50,1010
EntityType CamPivot, 1
EntityRadius CamPivot, 3
EntityType Camera, 1
EntityRadius Camera, 2
Global pistol=CreateCylinder()
EntityParent pistol,camera
PositionEntity pistol,EntityX(Camera)+1.5,EntityY(Camera)-2,EntityZ(Camera)+2
RotateEntity pistol,100,0,0
HideEntity pistol
Global muzzleglow2=CreateLight(pistol)
LightRange muzzleglow2,.0005
HideEntity muzzleglow2
LightColor muzzleglow2,255,255,0
Global t=0
Collisions 1,2,2,3
Function Loadlevel1()
light=CreateLight(2)
PositionEntity light,600,100,600
RotateEntity light,90,0,0
LightColor light,100,255,255
terrain=CreateTerrain(32)
PositionEntity terrain,0,-.02,0
ScaleEntity terrain,50,20,50
EntityType terrain,2
EntityPickMode terrain,2
city1=CreateCube()
PositionEntity city1,1000,1.5,1000
EntityType city1,2
EntityPickMode city1,2
ScaleEntity city1,50,20,50
enemies=0
SeedRnd 4
Repeat
e.enemy=New enemy
e\x=Rnd(1,1000)
e\y=4
e\z=Rnd(1,1000)
e\shape=CreateSphere()
PositionEntity e\shape,e\x,e\y,e\z
ScaleEntity e\shape,4,4,4
EntityType e\shape,3
EntityPickMode e\shape,3
enemies=enemies+1
Until enemies=10
CameraRange Camera,.2,1000
CameraFogMode Camera,1
CameraFogRange Camera,.2,999
CameraFogColor Camera,19,164,149
CameraClsColor Camera,0,255,255
While Not KeyHit(1)
controls()
Wend
Return
End Function
Function controls()
Color 255,0,0
If pistolselected=1
WritePixel 355,255,0
EndIf
If KeyDown( 42 ) =1
WalkSpeed# = 1.5
Else
WalkSpeed# = .5
EndIf
If KeyHit(2)
ShowEntity pistol
pistolselected=1
weaponout=1
End If
If FlyMode=0
If KeyDown(17) =1 Then MoveEntity CamPivot, 0, 0, WalkSpeed#
If KeyDown(31) =1 Then MoveEntity CamPivot, 0, 0, 0-WalkSpeed#
PositionEntity Camera, EntityX#( CamPivot ), EntityY#( CamPivot )+8, EntityZ#( CamPivot )
EndIf
If KeyDown(30) =1 Then MoveEntity CamPivot, -1, 0, 0
If KeyDown(32) =1 Then MoveEntity CamPivot, 1, 0, 0
If EntityCollided(CamPivot,2)
Gravity#=0
Else
Gravity#=-.5
EndIf
TranslateEntity CamPivot, 0, Gravity#, 0
TurnEntity CamPivot, 0, 0 -MouseXSpeed(), 0
TurnEntity Camera, MouseYSpeed(), 0, 0
RotateEntity CamPivot, EntityPitch#( CamPivot ), EntityYaw#( CamPivot ), 0
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
RotateEntity Camera, EntityPitch#( Camera ), EntityYaw#( CamPivot ), 0
If MouseHit(1)And pistolselected=1 And pistolammo>0
createbullet()
pistolammo=pistolammo-1
EndIf
If t=1
Text 0,20,"Enviroment picked"
EndIf
Text 0,40,"Press 1 to pull out pistol, aim with the dot"
Flip
UpdateWorld()
RenderWorld
HideEntity muzzleglow2
Return
ClearCollisions
End Function
Function createbullet( )
If pistolselected=1
ShowEntity muzzleglow2
EndIf
If weaponout=1
picked=CameraPick(camera,378,278)
If picked>1 Then
t=1
EndIf
If picked<2
blood=CreateSphere()
ShowEntity blood
EntityShininess blood,1
EntityColor blood,200,0,0
ScaleEntity blood,1,1,1
PositionEntity blood,PickedX(),PickedY(),PickedZ()
EntityType blood,1
EndIf
EndIf
End Function