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.
avoid gravity and rubber
- Psychophanta
- Addict
- Posts: 4997
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Lípetsk, Russian Federation
- Contact:
avoid gravity and rubber
http://www.zeitgeistmovie.com
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
Re: avoid gravity and rubber
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.
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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
- Psychophanta
- Addict
- Posts: 4997
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Lípetsk, Russian Federation
- Contact:
Re: avoid gravity and rubber
Sorry, but it is not so simple as you can test with this: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.
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)
http://www.zeitgeistmovie.com
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
Re: avoid gravity and rubber
use this
Code: Select all
SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0)
SetEntityAttribute(varilla,#PB_Entity_AngularSleeping,0.0)
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
- Psychophanta
- Addict
- Posts: 4997
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Lípetsk, Russian Federation
- Contact:
Re: avoid gravity and rubber
Waaaaa!Comtois wrote:use this
Code: Select all
SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0) SetEntityAttribute(varilla,#PB_Entity_AngularSleeping,0.0)
Comtois = my Hero
Thanks!
http://www.zeitgeistmovie.com
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
- Psychophanta
- Addict
- Posts: 4997
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Lípetsk, Russian Federation
- Contact:
Re: avoid gravity and rubber
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...
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...
http://www.zeitgeistmovie.com
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
Re: avoid gravity and rubber
I don't get 0.0 values. (on windows)but i get 0.0 every time...
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)
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.
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.
- Psychophanta
- Addict
- Posts: 4997
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Lípetsk, Russian Federation
- Contact:
Re: avoid gravity and rubber
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.
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.
http://www.zeitgeistmovie.com
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB