[PB 5.20] How apply physic on AttachEntityObject ?

Everything related to 3D programming
User avatar
falsam
Enthusiast
Enthusiast
Posts: 635
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

[PB 5.20] How apply physic on AttachEntityObject ?

Post by falsam »

[PB 5.20]
If you incline the ground, the ball through the wall. How can I do apply EntityPhysicBody() on AttachEntityObject ? (F2 Restart)

Code: Select all

EnableExplicit

Define.l Event

Define.f X, Y, Z
Global Window.i, Texture.i, Mesh.i, Material.i, Entity.i
Global Camera.i, Ground.i, Sphere.i
Global Wall1.i, Wall2.i, Wall3.i, Wall4.i
Global Node.i, Cube0, Cube1, Cube2, Cube3, Cube4
Global EntityMove.i

InitEngine3D()
InitKeyboard()
InitSprite()

ExamineDesktops()

Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "")
OpenWindowedScreen(WindowID(Window), 0, 0,DesktopWidth(0), DesktopHeight(0))

;
; Physics 
EnableWorldPhysics(#True) 

;
;Light and shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -10, 100, 20)
WorldShadows(#PB_Shadow_Additive)

;
; Camera 
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(173, 216, 230))

; 
; Texture (Ground, Obstacle, Sphere)
Texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(Texture))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()

;
; Material (Ground, Obstacle, Sphere)
Material = CreateMaterial(#PB_Any,TextureID(texture))
MaterialFilteringMode(Material, #PB_Material_Anisotropic, 6)

;
; Ground
Mesh = CreatePlane(#PB_Any, 100, 100, 10, 10, 10, 10)
Ground = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
EntityPhysicBody(Ground, #PB_Entity_StaticBody, 1, 0.5, 1)

;
; Obstacles
Mesh = CreateCube(#PB_Any, 1)

;Wall East
Wall1 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 50, 2, 0)
ScaleEntity(Wall1, 1, 4, 100)
EntityPhysicBody(Wall1, #PB_Entity_StaticBody, 1, 1, 1)
AttachEntityObject(Ground, "", EntityID(Wall1))

;Wall West
Wall2 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -50, 2, 0)
ScaleEntity(Wall2, 1, 4, 100)
EntityPhysicBody(Wall2, #PB_Entity_StaticBody, 1, 1, 1)
AttachEntityObject(Ground, "", EntityID(Wall2))

;Wall South
Wall3 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 50)
ScaleEntity(Wall3, 100, 4, 1)
EntityPhysicBody(Wall3, #PB_Entity_StaticBody, 1, 1, 1)
AttachEntityObject(Ground, "", EntityID(Wall3))

;Wall North
Wall4 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, -50)
ScaleEntity(Wall4, 100, 4, 1)
EntityPhysicBody(Wall4, #PB_Entity_StaticBody, 1, 1, 1)
AttachEntityObject(Ground, "", EntityID(Wall4))

;
; Création d'un node sur lequel seront attaché les entités.
; Le cube 0 sera au meme emplacement que le node.
Mesh = CreateCube(#PB_Any, 2)
Node = CreateNode(#PB_Any, 0, 0, 0) 

Cube0 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 0)
AttachNodeObject(Node, EntityID(Cube0))

Cube1 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 4, 2, 0)
AttachNodeObject(Node, EntityID(Cube1))

Cube2 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -4, 2, 0)
AttachNodeObject(Node, EntityID(Cube2))

Cube3 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 4)
AttachNodeObject(Node, EntityID(Cube3))

Cube4 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, -4)
AttachNodeObject(Node, EntityID(Cube4))

MoveNode(Node, 20, 0, 0, #PB_Absolute)

AttachEntityObject(Ground, "", NodeID(Node))


;
; Sphere
Mesh = CreateSphere(#PB_Any, 1.5)
Sphere = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 0)
EntityPhysicBody(Sphere, #PB_Entity_SphereBody, 1, 1, 9)

While #True
  Event = WindowEvent()
 
  If ExamineKeyboard()  
    EntityMove=#False
    
    If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Break
    EndIf  
    
    If KeyboardPushed(#PB_Key_Left)
      Z=0.3 : EntityMove=#True
    ElseIf KeyboardPushed(#PB_Key_Right)
      Z=-0.3 : EntityMove=#True
    EndIf
  
    If KeyboardPushed(#PB_Key_Up)
      X=-0.3 : EntityMove=#True  
    ElseIf KeyboardPushed(#PB_Key_Down)
      X=0.3 : EntityMove=#True
    EndIf
    
    If KeyboardPushed(#PB_Key_F2)
      RotateEntity(Ground, 0, 0, 0, #PB_Absolute)
      MoveEntity(Sphere, 0, 1, 0, #PB_Absolute)
    EndIf
    
  EndIf
  
  If EntityMove = #True
    ApplyEntityImpulse(Sphere, 0, 0.01, 0) ;(BugWare when the entity is fixed)
    RotateEntity(Ground, X, 0, Z, #PB_Relative)
  EndIf
  
  RotateNode(Node, 0, 1, 0, #PB_Relative) 
  
  ; Rotation de chacun des cubes
  ; Les deux premiers cubes étaient placés sur l'axe X
  ; Les deux suivant sur l'axe Z
  RotateEntity(cube1, -0.5, 0, 0, #PB_Relative)
  RotateEntity(cube2, 0.5, 0, 0, #PB_Relative)
  
  RotateEntity(cube3, 0, 0, -0.5, #PB_Relative)
  RotateEntity(cube4, 0, 0, 0.5, #PB_Relative)

  MoveCamera(Camera, 0, 40 , 110, #PB_Absolute)
  CameraLookAt(camera, 0, 0, 0)
  
  ; RenderWorld
  RenderWorld(40)
  FlipBuffers()
  
Wend
Last edited by falsam on Tue Aug 20, 2013 9:45 am, edited 3 times in total.

➽ 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: How apply physic on AttachEntityObject

Post by Bananenfreak »

You´re attaching the walls to itself, because every wall is Obstacle.

Please use

Code: Select all

EnableExplicit
.

Rewrite your code. I´m sure it will be functional.
Image
User avatar
falsam
Enthusiast
Enthusiast
Posts: 635
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: How apply physic on AttachEntityObject

Post by falsam »

Bananenfreak wrote:You´re attaching the walls to itself, because every wall is Obstacle.
No, each wall is attached to the ground.

Code: Select all

AttachEntityObject(Ground, "", EntityID(Obstacle))
Bananenfreak wrote:Rewrite your code. I´m sure it will be functional.
Sorry but i think the problem is not there.

➽ 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
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: How apply physic on AttachEntityObject

Post by Samuel »

Hello falsam,

I'm not sure how to solve your problem. I did notice that if you roll the ball slowly to the edges. The ball will sometimes bounces off.
So, maybe there is a better way to attach them. Maybe using nodes or joints? I know that's not much help, but someone will come along with all the answers to your problem. It's just not me.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 635
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: How apply physic on AttachEntityObject

Post by falsam »

Hello Samuel. I noticed this same behavior. Thank for your help :)

@Bananenfreak :The Code is updated in the first message (EnableExplicit) but my problem is still there.

I add a question: How to change the type of the body (Physic) associated with the node ?

➽ 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
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: How apply physic on AttachEntityObject

Post by DK_PETER »

Hi Falsam.

At least you got the ball moving :lol:
I think you're problem is related to mine. As soon you move your board, the physics parameters don't
apply to the new positions.
I'm still desperately working on a solution - so is ApplePi. (Maby Comtois, our Zen master, can find a solution to both our problems :wink: ).

I'll let you know if I find a way to make it work properly.

Best regards
Peter
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 635
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: How apply physic on AttachEntityObject

Post by falsam »

DK_PETER wrote:At least you got the ball moving :lol:
Yes my ball moves :mrgreen: But walls are ghosts. I'm afraid :mrgreen:

I tried another solution with a node, but the ball does not move.

Code: Select all

EnableExplicit

Define.l Event

Define.f X, Y, Z
Global Window.i, Texture.i, Mesh.i, Material.i, Entity.i
Global Camera.i, Ground.i, Sphere.i
Global Wall1.i, Wall2.i, Wall3.i, Wall4.i
Global Node.i
Global EntityMove.i

InitEngine3D()
InitKeyboard()
InitSprite()

ExamineDesktops()

Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "")
OpenWindowedScreen(WindowID(Window), 0, 0,DesktopWidth(0), DesktopHeight(0))

;
; Physics 
EnableWorldPhysics(#True) 

;
;Light and shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -10, 100, 20)
WorldShadows(#PB_Shadow_Additive)

;
; Camera 
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(173, 216, 230))

; 
; Texture (Ground, Obstacle, Sphere)
Texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(Texture))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()

;
; Material (Ground, Obstacle, Sphere)
Material = CreateMaterial(#PB_Any,TextureID(texture))
MaterialFilteringMode(Material, #PB_Material_Anisotropic, 6)

;
; Ground
Mesh = CreatePlane(#PB_Any, 100, 100, 10, 10, 10, 10)
Ground = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
EntityPhysicBody(Ground, #PB_Entity_StaticBody, 1, 0.5, 1)

;
; Obstacles
Mesh = CreateCube(#PB_Any, 1)

;Wall East
Wall1 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 50, 2, 0)
ScaleEntity(Wall1, 1, 4, 100)
EntityPhysicBody(Wall1, #PB_Entity_StaticBody, 1, 1, 1)

;Wall West
Wall2 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -50, 2, 0)
ScaleEntity(Wall2, 1, 4, 100)
EntityPhysicBody(Wall2, #PB_Entity_StaticBody, 1, 1, 1)

;Wall South
Wall3 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 50)
ScaleEntity(Wall3, 100, 4, 1)
EntityPhysicBody(Wall3, #PB_Entity_StaticBody, 1, 1, 1)

;Wall North
Wall4 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, -50)
ScaleEntity(Wall4, 100, 4, 1)
EntityPhysicBody(Wall4, #PB_Entity_StaticBody, 1, 1, 1)


Node = CreateNode(#PB_Any)
AttachNodeObject(Node, EntityID(Ground))
AttachNodeObject(Node, EntityID(Wall1))
AttachNodeObject(Node, EntityID(Wall2))
AttachNodeObject(Node, EntityID(Wall3))
AttachNodeObject(Node, EntityID(Wall4))

;
; Sphere
Mesh = CreateSphere(#PB_Any, 1.5)
Sphere = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 0)
EntityPhysicBody(Sphere, #PB_Entity_SphereBody, 1, 1, 9)

While #True
  Event = WindowEvent()
 
  If ExamineKeyboard()  
    EntityMove=#False
    
    If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Break
    EndIf  
    
    If KeyboardPushed(#PB_Key_Left)
      Z=0.3 : EntityMove=#True
    ElseIf KeyboardPushed(#PB_Key_Right)
      Z=-0.3 : EntityMove=#True
    EndIf
  
    If KeyboardPushed(#PB_Key_Up)
      X=-0.3 : EntityMove=#True  
    ElseIf KeyboardPushed(#PB_Key_Down)
      X=0.3 : EntityMove=#True
    EndIf
    
    If KeyboardPushed(#PB_Key_F2)
      RotateEntity(Ground, 0, 0, 0, #PB_Absolute)
      MoveEntity(Sphere, 0, 1, 0, #PB_Absolute)
    EndIf
    
  EndIf
  
  If EntityMove = #True
    ApplyEntityImpulse(Sphere, 0, 0.01, 0) ;(BugWare when the entity is fixed)
    RotateNode(Node, X, 0, Z, #PB_Relative)
  EndIf
  
  MoveCamera(Camera, 0, 40 , 110, #PB_Absolute)
  CameraLookAt(camera, 0, 0, 0)
  
  ; RenderWorld
  RenderWorld(40)
  FlipBuffers()
  
Wend

➽ 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
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: How apply physic on AttachEntityObject

Post by DK_PETER »

falsam wrote:
DK_PETER wrote:At least you got the ball moving :lol:
Yes my ball moves :mrgreen: But walls are ghosts. I'm afraid :mrgreen:

I tried another solution with a node, but the ball does not move.

Code: Select all

EnableExplicit

Define.l Event

Define.f X, Y, Z
Global Window.i, Texture.i, Mesh.i, Material.i, Entity.i
Global Camera.i, Ground.i, Sphere.i
Global Wall1.i, Wall2.i, Wall3.i, Wall4.i
Global Node.i
Global EntityMove.i

InitEngine3D()
InitKeyboard()
InitSprite()

ExamineDesktops()

Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "")
OpenWindowedScreen(WindowID(Window), 0, 0,DesktopWidth(0), DesktopHeight(0))

;
; Physics 
EnableWorldPhysics(#True) 

;
;Light and shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -10, 100, 20)
WorldShadows(#PB_Shadow_Additive)

;
; Camera 
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(173, 216, 230))

; 
; Texture (Ground, Obstacle, Sphere)
Texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(Texture))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()

;
; Material (Ground, Obstacle, Sphere)
Material = CreateMaterial(#PB_Any,TextureID(texture))
MaterialFilteringMode(Material, #PB_Material_Anisotropic, 6)

;
; Ground
Mesh = CreatePlane(#PB_Any, 100, 100, 10, 10, 10, 10)
Ground = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
EntityPhysicBody(Ground, #PB_Entity_StaticBody, 1, 0.5, 1)

;
; Obstacles
Mesh = CreateCube(#PB_Any, 1)

;Wall East
Wall1 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 50, 2, 0)
ScaleEntity(Wall1, 1, 4, 100)
EntityPhysicBody(Wall1, #PB_Entity_StaticBody, 1, 1, 1)

;Wall West
Wall2 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -50, 2, 0)
ScaleEntity(Wall2, 1, 4, 100)
EntityPhysicBody(Wall2, #PB_Entity_StaticBody, 1, 1, 1)

;Wall South
Wall3 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 50)
ScaleEntity(Wall3, 100, 4, 1)
EntityPhysicBody(Wall3, #PB_Entity_StaticBody, 1, 1, 1)

;Wall North
Wall4 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, -50)
ScaleEntity(Wall4, 100, 4, 1)
EntityPhysicBody(Wall4, #PB_Entity_StaticBody, 1, 1, 1)


Node = CreateNode(#PB_Any)
AttachNodeObject(Node, EntityID(Ground))
AttachNodeObject(Node, EntityID(Wall1))
AttachNodeObject(Node, EntityID(Wall2))
AttachNodeObject(Node, EntityID(Wall3))
AttachNodeObject(Node, EntityID(Wall4))

;
; Sphere
Mesh = CreateSphere(#PB_Any, 1.5)
Sphere = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 0)
EntityPhysicBody(Sphere, #PB_Entity_SphereBody, 1, 1, 9)

While #True
  Event = WindowEvent()
 
  If ExamineKeyboard()  
    EntityMove=#False
    
    If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Break
    EndIf  
    
    If KeyboardPushed(#PB_Key_Left)
      Z=0.3 : EntityMove=#True
    ElseIf KeyboardPushed(#PB_Key_Right)
      Z=-0.3 : EntityMove=#True
    EndIf
  
    If KeyboardPushed(#PB_Key_Up)
      X=-0.3 : EntityMove=#True  
    ElseIf KeyboardPushed(#PB_Key_Down)
      X=0.3 : EntityMove=#True
    EndIf
    
    If KeyboardPushed(#PB_Key_F2)
      RotateEntity(Ground, 0, 0, 0, #PB_Absolute)
      MoveEntity(Sphere, 0, 1, 0, #PB_Absolute)
    EndIf
    
  EndIf
  
  If EntityMove = #True
    ApplyEntityImpulse(Sphere, 0, 0.01, 0) ;(BugWare when the entity is fixed)
    RotateNode(Node, X, 0, Z, #PB_Relative)
  EndIf
  
  MoveCamera(Camera, 0, 40 , 110, #PB_Absolute)
  CameraLookAt(camera, 0, 0, 0)
  
  ; RenderWorld
  RenderWorld(40)
  FlipBuffers()
  
Wend
I've could have told you that. :mrgreen:
I've tried jointmotor and nodes - No go at all. Still trying, though..
The problem is, that the physics stays at the original positions and does not update to new positions.
(Try tilting your board, only slightly to make the ball roll and then tilt the board back.
(Collisions then occurs as expected, but deviate from boards org. pos and everything goes out of sync).
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: How apply physic on AttachEntityObject

Post by applePi »

it is possibly related to the static Geometry physics problem, i have experimented with a hollow plane , without applying very tiny force to the sphere it will sink at this place if you wait a little and then rotate the plane (comment line 74 :ApplyEntityImpulse(Sphere, 0, 0.00001, 0) )
Image
but apply tiny force at line 74 and i can't make it to sink, if you want to try my model here the hollow ground mesh
http://www.mediafire.com/?mzhz4i1vo4zbys4
but still the move needs more tunning since the sphere sometimes stick to the wall.
note: i have added WorldGravity(-200) just to observe more the sphere move
using falsam code:

Code: Select all

Define.f X, Y, Z

InitEngine3D()
InitKeyboard()
InitSprite()
#mat = 200
#Ground = 210
ExamineDesktops()

Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "")
OpenWindowedScreen(WindowID(Window), 0, 0,DesktopWidth(0), DesktopHeight(0))
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures/"       , #PB_3DArchive_FileSystem)
;
; Physics 
EnableWorldPhysics(#True) 

;
;Light and shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -10, 100, 20)
WorldShadows(#PB_Shadow_Additive)

;
; Camera 
Camera = CreateCamera(#PB_Any,0,0,400,400)
CameraBackColor(Camera, RGB(173, 216, 230))


; Material (Ground, Obstacle, Sphere)
CreateMaterial(#mat, LoadTexture(#mat, "MRAMOR6X6.jpg"))
;MaterialFilteringMode(#mat, #PB_Material_Anisotropic, 6)
MaterialCullingMode(#mat, #PB_Material_NoCulling )

; Ground

LoadMesh(#Ground, "ground_x.mesh")
CreateEntity(#Ground, MeshID(#Ground), MaterialID(#mat), 0,0,0)
ScaleEntity(#Ground, 0.03,0.01,0.01)
RotateEntity(#Ground,0,0,180)
EntityPhysicBody(#Ground, #PB_Entity_StaticBody)

; Sphere
Mesh = CreateSphere(#PB_Any, 5, 50,50)
Sphere = CreateEntity(#PB_Any, MeshID(Mesh), #PB_Material_None , 0, 10, 0)
EntityPhysicBody(Sphere, #PB_Entity_SphereBody, 3, 1, 1)
MoveCamera(Camera, 0, 200 , -250, #PB_Absolute)
  
  CameraLookAt(camera, 0, 0, 0)
WorldGravity(-200)  
While #True
  Event = WindowEvent()
 
  If ExamineKeyboard()  
    EntityMove=#False
    
    If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Break
    EndIf  
    
    If KeyboardPushed(#PB_Key_Left)
      Z=-0.3 : EntityMove=#True
    ElseIf KeyboardPushed(#PB_Key_Right)
      Z=0.3 : EntityMove=#True
    EndIf
  
    If KeyboardPushed(#PB_Key_Up)
      X=-0.3 : EntityMove=#True  
    ElseIf KeyboardPushed(#PB_Key_Down)
      X=0.3 : EntityMove=#True
    EndIf
    
  EndIf
  ApplyEntityImpulse(Sphere, 0, 0.00001, 0) 
  
  If EntityMove = #True
    ;ApplyEntityImpulse(Sphere, 1, 0, 0) ;(BugWare when the entity is fixed)
    RotateEntity(#Ground, X, 0, Z, #PB_Relative)
  EndIf
  
  
  ; RenderWorld
  RenderWorld(40)
  FlipBuffers()
  
Wend
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: How apply physic on AttachEntityObject

Post by DK_PETER »

Neat example ApplePi. :-)
It's at least somewhat doable this way.
I just saw Comtois here at the forum awhile ago.
I wonder if he's coming back and puts us all to shame. :oops:
He has a tendency to do so :lol:
I'm still trying to get the original to work, though..Both falsams and mine.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: How apply physic on AttachEntityObject

Post by Comtois »

DK_PETER wrote:I just saw Comtois here at the forum awhile ago.
I wonder if he's coming back and puts us all to shame. :oops:
He has a tendency to do so :lol:
I am far from having an answer to everything, I learn a lot through codes and comments from all participants of this forum :)
Please correct my english
http://purebasic.developpez.com/
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: How apply physic on AttachEntityObject

Post by DK_PETER »

Comtois wrote:
DK_PETER wrote:I just saw Comtois here at the forum awhile ago.
I wonder if he's coming back and puts us all to shame. :oops:
He has a tendency to do so :lol:
I am far from having an answer to everything, I learn a lot through codes and comments from all participants of this forum :)
Arrrrh... My dear Comtois. Though it's good to know, that your not infallibe - I still have faith in you. :P
You know why? Right now I'm beating myself with a bag of rice crispies. You wouldn't think of doing that, would you? :lol:

Edit: Time is now 00:52 and I'm no way near a real solution. Gonna get some shuteye and look at this again tomorrow.. :?
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: How apply physic on AttachEntityObject

Post by Bananenfreak »

I found the solution:

When you use StaticGeometry as Physicsbody for an Entity, you can move and rotate the Entity, but the physicsbody stays at the same Position.
Try to Speed up the ball and then rotate the plane to the original Position. Ball will bounce off the walls. If you rotate it, the ball flies through the wall.

But why only the Walls have this effect? The plane not... (Bug?)
Image
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: How apply physic on AttachEntityObject

Post by DK_PETER »

Bananenfreak wrote:I found the solution:

When you use StaticGeometry as Physicsbody for an Entity, you can move and rotate the Entity, but the physicsbody stays at the same Position.
Try to Speed up the ball and then rotate the plane to the original Position. Ball will bounce off the walls. If you rotate it, the ball flies through the wall.

But why only the Walls have this effect? The plane not... (Bug?)
I've been battling with walls, boxes etc non-stop since yesterday.
For now..The only solution I've come up with is 'faking' a board tilt using a camera attached to a node
and spin the 'sucker' to obtain momentum..

I haven't posted my new example yet, since everything is a mess and I can't seem to get it right...for now.

Still hoping for the perfect solution, though.

Best regards
Peter
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: [PB 5.20] How apply physic on AttachEntityObject ?

Post by DK_PETER »

That's it! I'm throwing in the towel! Edit: for now.
falsam. I think I found a workaround to your problem, but NOT mine:

Code: Select all

Define.f X, Y, Z

InitEngine3D()
InitKeyboard()
InitSprite()

ExamineDesktops()

Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "")
OpenWindowedScreen(WindowID(Window), 0, 0,DesktopWidth(0), DesktopHeight(0))

;
; Physics
EnableWorldPhysics(#True)

;
;Light and shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -10, 100, 20)
WorldShadows(#PB_Shadow_Additive)

;
; Camera
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(173, 216, 230))

;
; Texture (Ground, Obstacle, Sphere)
Texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(Texture))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()

;
; Material (Ground, Obstacle, Sphere)
Material = CreateMaterial(#PB_Any,TextureID(texture))
MaterialFilteringMode(Material, #PB_Material_Anisotropic, 6)

;
; Ground
Mesh = CreatePlane(#PB_Any, 100, 100, 10, 10, 10, 10)
Ground = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
EntityPhysicBody(Ground, #PB_Entity_StaticBody, 1, 0.5, 1)

;
; Obstacles
Mesh = CreateCube(#PB_Any, 1)

;Wall East
Obstacle = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 50, 2, 0)
ScaleEntity(Obstacle, 1, 4, 100)
EntityPhysicBody(Obstacle, #PB_Entity_StaticBody, 1, 1, 1)
AttachEntityObject(Ground, "", EntityID(Obstacle))

;Wall West
Obstacle = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -50, 2, 0)
ScaleEntity(Obstacle, 1, 4, 100)
EntityPhysicBody(Obstacle, #PB_Entity_StaticBody, 1, 1, 1)
AttachEntityObject(Ground, "", EntityID(Obstacle))

;Wall South
Obstacle = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 50)
ScaleEntity(Obstacle, 100, 4, 1)
EntityPhysicBody(Obstacle, #PB_Entity_StaticBody, 1, 1, 1)
AttachEntityObject(Ground, "", EntityID(Obstacle))

;Wall North
Obstacle = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, -50)
ScaleEntity(Obstacle, 100, 4, 1)
EntityPhysicBody(Obstacle, #PB_Entity_StaticBody, 1, 1, 1)
AttachEntityObject(Ground, "", EntityID(Obstacle))

;
; Sphere
Mesh = CreateSphere(#PB_Any, 1.5)
Sphere = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 0)
EntityPhysicBody(Sphere, #PB_Entity_SphereBody, 1, 1, 9)

boundaryMesh.i = CreateCube(#PB_Any, 10)
boundaryMeshID = CreateEntity(#PB_Any, MeshID(boundaryMesh),#PB_Material_None)
ScaleEntity(boundaryMeshID, 10,10,10)
EntityPhysicBody(boundaryMeshID, #PB_Entity_StaticBody, 1, 1, 9)
MoveEntity(boundaryMeshID,0,0,0)
HideEntity(boundaryMeshID,1)
While #True
  Event = WindowEvent()
 
  If ExamineKeyboard() 
    EntityMove=#False
   
    If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Break
    EndIf 
   
    If KeyboardPushed(#PB_Key_Left)
      Z=0.3 : EntityMove=#True
    ElseIf KeyboardPushed(#PB_Key_Right)
      Z=-0.3 : EntityMove=#True
    EndIf
 
    If KeyboardPushed(#PB_Key_Up)
      X=-0.3 : EntityMove=#True 
    ElseIf KeyboardPushed(#PB_Key_Down)
      X=0.3 : EntityMove=#True
    EndIf
   
    If KeyboardPushed(#PB_Key_F2)
      RotateEntity(Ground, 0, 0, 0, #PB_Absolute)
      MoveEntity(Sphere, 0, 1, 0, #PB_Absolute)
    EndIf
   
  EndIf
 
  If EntityMove = #True
    ApplyEntityImpulse(Sphere, 0, 0.01, 0) ;(BugWare when the entity is fixed)
    RotateEntity(Ground, X, 0, Z, #PB_Relative)
  EndIf
 
  MoveCamera(Camera, 0, 40 , 110, #PB_Absolute)
  CameraLookAt(camera, 0, 0, 0)
 
  ; RenderWorld
  RenderWorld(40)
  FlipBuffers()
 
Wend
Bullet physics is weird --- and extremely competent...Odd combination.
Seems like Rigid bodies which don't move for a certain amount of time gets automatically disabled for performance reasons:
Oh..well...Time for some chow and then onwards with test number 8287383774.

Best regards
Peter
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Post Reply