It is currently Thu Nov 15, 2018 9:50 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: avoid gravity and rubber
PostPosted: Wed Aug 15, 2018 7:44 am 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4480
Location: Spa, relaxing and thinking, and learning...
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.

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
While (world==business) {world+=mafia}


Top
 Profile  
Reply with quote  
 Post subject: Re: avoid gravity and rubber
PostPosted: Wed Aug 15, 2018 9:50 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1159
Location: Germany, Glienicke
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.

_________________
ImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: avoid gravity and rubber
PostPosted: Thu Aug 16, 2018 9:12 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4480
Location: Spa, relaxing and thinking, and learning...
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:
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
While (world==business) {world+=mafia}


Top
 Profile  
Reply with quote  
 Post subject: Re: avoid gravity and rubber
PostPosted: Thu Aug 16, 2018 9:34 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1403
Location: Doubs - France
use this

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

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: avoid gravity and rubber
PostPosted: Fri Aug 17, 2018 8:44 am 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4480
Location: Spa, relaxing and thinking, and learning...
Comtois wrote:
use this

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


Waaaaa!
Comtois = my Hero :!:

Thanks!

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
While (world==business) {world+=mafia}


Top
 Profile  
Reply with quote  
 Post subject: Re: avoid gravity and rubber
PostPosted: Fri Aug 24, 2018 5:11 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4480
Location: Spa, relaxing and thinking, and learning...
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... :(

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
While (world==business) {world+=mafia}


Top
 Profile  
Reply with quote  
 Post subject: Re: avoid gravity and rubber
PostPosted: Sat Aug 25, 2018 7:54 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 742
Location: Denmark
Quote:
but i get 0.0 every time...


I don't get 0.0 values. (on windows)

Code:
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)
 

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 7/10, Intel 6800K, Gtx 970, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: avoid gravity and rubber
PostPosted: Sat Aug 25, 2018 8:54 am 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4480
Location: Spa, relaxing and thinking, and learning...
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.

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
While (world==business) {world+=mafia}


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye