Page 1 of 1

avoid gravity and rubber

Posted: Wed Aug 15, 2018 7:44 am
by Psychophanta
Hello, I have got a 0 gravity , I have tried to do collissions with some objects , and after collisions I have noticed every object acquire lower and lower speed ... until it stops any movement.
Any trick to maintain the speed and rotation of an entity?
Thanks in advance.

Re: avoid gravity and rubber

Posted: Wed Aug 15, 2018 9:50 am
by STARGÅTE
If you create your bodies, you have to set the Restitution and the Friction values.
SetEntityAttribute().

For the conservation of velocity (or energy) you have to set Restitution = 1 and Friction = 0.
But be carefully with such settings. In physical simulations it more stable to have restitution < 1 and frictions > 0.

Re: avoid gravity and rubber

Posted: Thu Aug 16, 2018 9:12 pm
by Psychophanta
STARGÅTE wrote:If you create your bodies, you have to set the Restitution and the Friction values.
SetEntityAttribute().

For the conservation of velocity (or energy) you have to set Restitution = 1 and Friction = 0.
But be carefully with such settings. In physical simulations it more stable to have restitution < 1 and frictions > 0.
Sorry, but it is not so simple as you can test with this:

Code: Select all

IncludeFile #PB_Compiler_Home+"examples/3d/Screen3DRequester.pb"
If InitEngine3D()=0
  MessageRequester("Error","The 3D Engine can't be initialized",0):End
EndIf
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/fonts", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite():InitKeyboard():InitMouse()
If Screen3DRequester()=0
  MessageRequester("Error","Screen3DRequester can't be initialized",0):End
EndIf
; Textura
CreateTexture(0,128,128)
StartDrawing(TextureOutput(0))
Box(0,0,128,128,$EEEEEE)
StopDrawing()
WorldGravity(0.0)
; Materiales
CreateMaterial(2,TextureID(0))
SetMaterialColor(2,2,$D0B86B)
; Entidades
CreateCylinder(3,0.1,7,20,1,1)
varilla.i=CreateEntity(#PB_Any,MeshID(3),MaterialID(2))
MoveEntity(varilla,0,8,0,#PB_Absolute)
CreateEntityBody(varilla,#PB_Entity_CylinderBody,1.0,1.0,0.0)
; Camara
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,12,20,#PB_Absolute)
CameraLookAt(0,0,5,0)
; Luz
CreateLight(0,RGB(160,160,254),0,300,0)
AmbientColor(RGB(105,105,105))

SetEntityAttribute(varilla,#PB_Entity_Restitution,1.0)
SetEntityAttribute(varilla,#PB_Entity_Friction,0.0)
Repeat
  Screen3DEvents()
  If ExamineKeyboard()
    If KeyboardReleased(#PB_Key_M)
      ApplyEntityImpulse(varilla,0.14,0,0,0,-2,0)
    EndIf
  EndIf
  TimeSinceLastFrame.i=RenderWorld(50)
  Screen3DStats()
  FlipBuffers():Delay(9)
Until KeyboardPushed(#PB_Key_Escape)
 

Re: avoid gravity and rubber

Posted: Thu Aug 16, 2018 9:34 pm
by Comtois
use this

Code: Select all

SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0)
SetEntityAttribute(varilla,#PB_Entity_AngularSleeping,0.0)

Re: avoid gravity and rubber

Posted: Fri Aug 17, 2018 8:44 am
by Psychophanta
Comtois wrote:use this

Code: Select all

SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0)
SetEntityAttribute(varilla,#PB_Entity_AngularSleeping,0.0)
Waaaaa!
Comtois = my Hero :!:

Thanks!

Re: avoid gravity and rubber

Posted: Fri Aug 24, 2018 5:11 pm
by Psychophanta
Hi again Comtois.
After doing that, and after bar is in movement, how can i get linear velocity or angular velocity of the bar?
I tried it with GetEntityAttribute() and several atributes to get it like #PB_Entity_LinearVelocity, #PB_Entity_LinearSleeping, but i get 0.0 every time... :(

Re: avoid gravity and rubber

Posted: Sat Aug 25, 2018 7:54 am
by DK_PETER
but i get 0.0 every time...
I don't get 0.0 values. (on windows)

Code: Select all

IncludeFile #PB_Compiler_Home+"examples/3d/Screen3DRequester.pb"
Global lin.f, ang.f
If InitEngine3D()=0
  MessageRequester("Error","The 3D Engine can't be initialized",0):End
EndIf
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/fonts", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite():InitKeyboard():InitMouse()
If Screen3DRequester()=0
  MessageRequester("Error","Screen3DRequester can't be initialized",0):End
EndIf
; Textura
CreateTexture(0,128,128)
StartDrawing(TextureOutput(0))
Box(0,0,128,128,$EEEEEE)
StopDrawing()
WorldGravity(0.0)
; Materiales
CreateMaterial(2,TextureID(0))
SetMaterialColor(2,2,$D0B86B)
; Entidades
CreateCylinder(3,0.1,7,20,1,1)
varilla.i=CreateEntity(#PB_Any,MeshID(3),MaterialID(2))
MoveEntity(varilla,0,8,0,#PB_Absolute)
CreateEntityBody(varilla,#PB_Entity_CylinderBody,1.0,1.0,0.0)
; Camara
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,12,20,#PB_Absolute)
CameraLookAt(0,0,5,0)
; Luz
CreateLight(0,RGB(160,160,254),0,300,0)
AmbientColor(RGB(105,105,105))

SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0)
SetEntityAttribute(varilla,#PB_Entity_AngularSleeping, 0.0)

Repeat
  Screen3DEvents()
  If ExamineKeyboard()
    If KeyboardReleased(#PB_Key_M)
      ApplyEntityImpulse(varilla,0.14,0,0,0,-2,0)
    EndIf
  EndIf
  lin = GetEntityAttribute(varilla,#PB_Entity_LinearVelocity)
  ang = GetEntityAttribute(varilla,#PB_Entity_AngularVelocity)
  TimeSinceLastFrame.i=RenderWorld(50)
  Screen3DStats()

  SetWindowTitle(0, StrF(lin) + " - " + StrF(ang))
  FlipBuffers():Delay(9)
Until KeyboardPushed(#PB_Key_Escape)
 

Re: avoid gravity and rubber

Posted: Sat Aug 25, 2018 8:54 am
by Psychophanta
You are right DK_PETER,
my problem was i made a collision a ball with the bar, and in the main loop i stupidly retrieved the result of the bar attributes only one time (just after the ball impulsation), and now i've corrected: I retrieve the attribute of the bar one time per loop.

Thanks.