Ooops
November 30, 2020, 02:39:08 AM

Author Topic: [bb] Simple Wheel Physics by MCP [ 1+ years ago ]  (Read 1087 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Simple Wheel Physics by MCP [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Simple Wheel Physics
Author : MCP
Posted : 1+ years ago

Description : Using Circumference to calculate wheel rotation based on velocity

Code :
Code: BlitzBasic
  1. ;*** wheel circumference calculation
  2. ;*** R Ferriby 2006
  3.  
  4. Graphics3D 800,600,32
  5. SetBuffer BackBuffer()
  6. light%=CreateLight() : PositionEntity light,50,50,-50
  7. camera%=CreateCamera()
  8.  
  9. wheel_radius#=10.0   ;<-- enter your own values here
  10.  
  11. ;*** create some suitable ground
  12. plane%=CreatePlane()
  13. EntityColor plane,0,255,0
  14. EntityAlpha plane,0.5
  15. PositionEntity plane,0,-wheel_radius,0
  16. mirror%=CreateMirror()
  17. PositionEntity mirror,0,-wheel_radius,0
  18.  
  19. ;*** create a simple wheel object
  20. wheel%=CreateCylinder(12) : ScaleMesh wheel,1,0.05,1 : RotateMesh wheel,0,0,90
  21. ScaleEntity wheel,wheel_radius,wheel_radius,wheel_radius
  22.  
  23. wheel_diameter#=wheel_radius+wheel_radius
  24.  
  25. circumference#=wheel_diameter*Pi
  26.  
  27. axel%=CreatePivot() : EntityParent wheel,axel : PositionEntity axel,0,0,100,1
  28. TurnEntity axel,0,-90,0
  29.  
  30. velocity#=0.0
  31. While Not KeyHit(1)
  32.         If KeyDown(203)
  33.                 If velocity>-1.0
  34.                         velocity=velocity-0.02
  35.                 EndIf
  36.         EndIf
  37.         If KeyDown(205)
  38.                 If velocity<1.0
  39.                         velocity=velocity+0.02
  40.                 EndIf
  41.         EndIf
  42.         If velocity<0.0
  43.                 velocity=velocity+0.01
  44.                 If velocity>0.0
  45.                         velocity=0.0
  46.                 Else
  47.                         If velocity<-1.0
  48.                                 velocity=-1.0
  49.                         EndIf
  50.                 EndIf
  51.         EndIf
  52.         If velocity>0.0
  53.                 velocity=velocity-0.01
  54.                 If velocity<0.0
  55.                         velocity=0.0
  56.                 Else
  57.                         If velocity>1.0
  58.                                 velocity=1.0
  59.                         EndIf
  60.                 EndIf
  61.         EndIf
  62.         ;*** simply move the axel the specified distance
  63.         MoveEntity axel,0,0,velocity
  64.        
  65.         ;*** magic bit to calculate wheel rotation based on distance traveled
  66.         rotation#=360.0*(velocity/circumference)
  67.         TurnEntity wheel,rotation,0,0
  68.        
  69.         RenderWorld
  70.         Text 0,0,"wheel radius="+wheel_radius
  71.         Text 0,15,"wheel circumference="+circumference
  72.         Text 0,30,"velocity="+velocity
  73.         Text 0,50,"Left cursor to Roll left"
  74.         Text 0,65,"Right cursor to Roll right"
  75.         Text 0,80,"Esc - Quit"
  76.         Flip
  77. Wend
  78. End


Comments :


puki(Posted 1+ years ago)

 I quite like this - I have no use for it - but I like it.


MCP(Posted 1+ years ago)

 Thanks puki - I'm having a go at tank tracks now, tis proving a tad difficult :P


IKG(Posted 1+ years ago)

 Reminds me of how I programmed the "jumping" physics in my latest game. Cool stuff :)


Weetbix(Posted 1+ years ago)

 Very cool, thanks for sharing :) any chance your sharing the tank tracks?


MCP(Posted 1+ years ago)

 Thanks for your comments ppl -  The tank track code will be available for everyone, IF I can ever get it to work!!!Cheers :)


Weetbix(Posted 1+ years ago)

 Thanks alot :) keep trying and good luck!


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal