[PB5.22] [3D] Entity is no longer active when sleeping

All bugs related to the 3D engine
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

[PB5.22] [3D] Entity is no longer active when sleeping

Post by falsam »

Snippet Code

Code: Select all

EnableExplicit

Enumeration
  #Mainform
EndEnumeration

Global WindowStyle.i=#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered
Global Event.l

Global Camera, Mesh, Entity, Player, PlayerSpeed.f

Procedure GameStart()
  InitEngine3D()
  InitKeyboard()
  InitSprite()
      
  OpenWindow(#Mainform,0,0,1024,768, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#Mainform),0,0,1024,768,0, 0, 0)

  KeyboardMode(#PB_Keyboard_International)

  ;Ground
  Mesh = CreatePlane(#PB_Any, 40, 40, 1, 1, 1, 1)
  Entity = CreateEntity(#PB_Any, MeshID(Mesh), #PB_Material_None, 0, 0, 0)
  EntityPhysicBody(Entity, #PB_Entity_StaticBody, 2, 0, 1)

  ;Player
  Mesh = CreateCube (#PB_Any, 1)
  Player = CreateEntity(#PB_Any, MeshID(Mesh), #PB_Material_None, 0, 1, 0)
  EntityPhysicBody(Player, #PB_Entity_BoxBody, 0.5, 0.5, 0.1)
  
  ;Ambience
  AmbientColor(RGB(127, 127, 127))
  CreateLight(#PB_Any,RGB(151, 251, 151), -1.8, 10, 5)
  WorldShadows(#PB_Shadow_Additive)

  ; Camera 
  Camera = CreateCamera(#PB_Any,0,0,100,100)
  CameraBackColor(Camera, RGB(145, 182, 201)) 

EndProcedure

GameStart()

Repeat
  Repeat
    Event  = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
        
    EndSelect
  Until Event = 0
  
  If ExamineKeyboard()    
    If KeyboardPushed (#PB_Key_Escape)
      Break
    EndIf
  EndIf
  
  If KeyboardPushed (#PB_Key_Up)
    PlayerSpeed = -  1
  ElseIf KeyboardPushed (#PB_Key_Down)
    PlayerSpeed  =  1
  Else
    PlayerSpeed = 0
  EndIf
    
  If KeyboardPushed (#PB_Key_Left)
    RotateEntity(Player, 0, 1.5, 0, #PB_Relative)
  ElseIf KeyboardPushed (#PB_Key_Right)
    RotateEntity(Player, 0, -1.5, 0, #PB_Relative)
  EndIf
  
  If PlayerSpeed <> 0    
    Debug GetEntityAttribute(Player, #PB_Entity_IsActive)
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
  EndIf
  
  CameraFollow(Camera, EntityID(Player), 0, EntityY(Player) + 2, 6, 0.08, 0.08, #True)
  
  ClearScreen(RGB(0, 0, 0))
  RenderWorld(80)
  FlipBuffers()  
ForEver
:idea: Quick-fix : Insert DisableEntityBody(Player, 0) (Thank Comtois) after If PlayerSpeed <> 0

Code: Select all

  If PlayerSpeed <> 0
    DisableEntityBody(Player, 0)
    Debug GetEntityAttribute(Player, #PB_Entity_IsActive)
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
  EndIf

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: [PB5.22] [3D] Entity is no longer active when sleeping

Post by Bananenfreak »

I also noticed if a entity with physicsbody is longer (under 1 sec) without any velocity, force, Impulse,... it will be inactive. In my case, there was no possibility to set it on active (No Chance to use MoveEntity, EntityImpulse,...).
Image
Post Reply