Enititypick
Blitz3D Forums/Blitz3D Beginners Area/Enititypick
| ||
Hello, I've been messing with this for the past couple of hours and I can't figure it out. I've tried everyway I can think of, even looked at code snips online with no luck. cube = CreateCube() PositionEntity cube,0,8,0 ScaleEntity cube,5,5,5 EntityColor cube,0,255,255 EntityPickMode cube,3 If MouseHit(1) Then CameraPick(cam,MouseX(),MouseY()) pick = PickedEntity() EndIf If pick = cube Then msg = True EndIf If msg=True Then Text 0,0,"Worked" EndIf Hopefully one of you guys could help me. I'd really appreciate it! |
| ||
G'day Jammer429. Just tried it & it works. Just make sure any text goes after the renderworld & before flip. Graphics3D 800,600,0,2 SetBuffer BackBuffer() cam = CreateCamera() cube = CreateCube() PositionEntity cube,-2,0,8 EntityColor cube,0,255,255 EntityPickMode cube,3 cube2 = CreateCube() PositionEntity cube2,2,0,8 EntityColor cube2,255,0,255 EntityPickMode cube2,3 While Not KeyDown (1) If MouseHit(1) Then CameraPick(cam,MouseX(),MouseY()) pick = PickedEntity() EndIf If pick = cube Or pick = cube2 msg = True End If If pick = 0 msg = False End If UpdateWorld RenderWorld If msg=True Then Text 0,0,"Worked " +pick EndIf Flip Wend End |
| ||
I'm a noob in any kinda of coding. I don't know how to place it in the code for it to be clean and efficient.. Here is my entire code..Graphics3D 1024,768,32,2 SetBuffer BackBuffer() AntiAlias enable ; Data Structures Global Type_Cell = 1 Global Type_Cam = 2 Global Type_Fps = 3 Light = CreateLight() ; set up scene PositionEntity(Light,0,0,0) Global cam = CreateCamera() Global camx = 0 Global camz = 0 Global camy# = 15 PositionEntity(cam, camx,camy,camz) EntityParent cam, arm EntityType cam, Type_Cam ; Globals Global Jailsound = LoadSound("Media\Sounds\Jail\Jail.ogg") Global MainMenubg = LoadImage("Media\Textures\MainMenu.png") Global weap = False Global Anim = False Global started = False Global player = LoadAnimMesh("Media\Meshes\Actors\Arm\Arm.b3d") Global grunt = LoadSound("Media\sounds\Player\Male_Grunt.ogg") While Not KeyDown(1) ; Main Loop Text 0,20,"Triangles Rendered: "+TrisRendered() MainMenu() ; Player Controls Anim() PlayerData() ; Mouse Look mxs# = mxs# + MouseXSpeed() ;mys# = mys# + MouseYSpeed() If mxs# > 360 Then mxs# = 0 If mxs# < 0 Then mxs# = 360 ;If mys# > 80 Then mys# = 80 ;If mys# < -80 Then mys = -80 ;RotateEntity cam, mys#,-mxs#,0 Collisions Type_Cam,Type_Cell,2,2 ; Gravity ;TranslateEntity(cam, 0,-0.1,0) UpdateWorld() RenderWorld() Wend Function MainMenu() ; Main Menu If started = False DrawImage MainMenubg,0,0 start_btn = LoadImage("Media\Gui\btn_start.png") DrawImage start_btn,420,600 s_btnx = 420 s_btny = 600 DrawImage start_btn,s_btnx,s_btny s_btnw =ImageWidth(start_btn) s_btnh =ImageHeight(start_btn) If ( MouseX() > s_btnx ) And ( MouseX() < (s_btnx+s_btnw) ) If ( MouseY() > s_btny ) And ( MouseY() < (s_btny+s_btnh) ) over = True EndIf EndIf EndIf If over = True If MouseDown(1) Jail() FreeImage (start_btn) FreeImage (MainMenubg) Cls EndIf EndIf Flip(VWait) End Function Function PlayerData() ; Player Data i# = .010 If weap = False PositionEntity player,-4,-15,-1 ScaleEntity player, 5,5,5 EntityParent player, cam Anim() EndIf ; player movement If KeyDown(42) i# = .025 EndIf If KeyDown(30) Then TurnEntity cam, 0,.15,0 If KeyDown(32) Then TurnEntity cam, 0,-.15,0 If KeyDown(17) Then MoveEntity cam, 0,0,i If KeyDown(31) Then MoveEntity cam, 0,0,-.010 End Function Function Anim() If MouseDown(1) And started = True Animate player,3,.2 If MouseHit(1) PlaySound(grunt) EndIf EndIf End Function Function Jail() ; Starting zone Cls started = True ;Room ;HidePointer PlayerData() FreeImage (start_btn) Cls PlaySound(Jailsound) Cell = LoadMesh("Cell\cell.b3d") PositionEntity(Cell,0,0,0) ScaleEntity(Cell,1.2,1.2,1.2) EntityType Cell, Type_Cell Collisions Type_Cell,Type_Cam ,2,1 ; clickable entity test cube = CreateCube() PositionEntity cube,0,8,0 ScaleEntity cube,5,5,5 EntityColor cube,0,255,255 EntityPickMode cube,1 If MouseHit(1) Then CameraPick(cam,MouseX(),MouseY()) pick = PickedEntity() EndIf If pick = cube Then msg = True EndIf If msg=True Then Text 0,0,"Worked" EndIf End Function and thanks for the quick response. I really appreciate the help. |
| ||
I guess I confused about how much stuff to actually put inside the main loop, rather then making a function for something and calling it within the main loop |
| ||
I still class myself as a noob mate. Been here for a few years but don't get a lot of chance to get stuck right into coding & when i do get the chance it can take me a fair while to get my head back around what i have been doing due to long breaks between coding sessions. I am reluctant to offer advice with a lot things because i don't want to give you or anyone else the wrong info. But as far as i am aware the "Flip" function should be called after the "RenderWorld" Function & before the "Wend" Function. Any "Text" should be placed between the "RenderWorld" & "Flip" Function. The way i started was to put everything inside the main loop just to play around and get things working the way i want them to. Once i got things working i would then go through, break the code up into functions & clean it up. Everyone learns in their own way. Hope this helps. |