Just wondering how best to make the cab drive around and the trailer follow in the correct way? they are 2 different b3d models.
the truck in question
the truck in question
;setup graphics Graphics3D 800, 600, 0, 2 SetBuffer BackBuffer() CreateLight() camera = CreateCamera() PositionEntity camera, 0, 2, -8 ;create cab cab = CreateCube() ScaleEntity cab, 0.4, 0.4, 0.4 ;create pivot pivot = CreateSphere(8,cab) ScaleEntity pivot, 0.2, 0.2, 0.2 EntityColor pivot, 0, 255, 0 EntityOrder pivot, -1 ;pivot=CreatePivot(cab) PositionEntity pivot, 0, -1, 0 ;create trailer trailer = CreateCube() ScaleEntity trailer, 0.39, 0.4, 1 EntityColor trailer, 255, 0, 0 PositionEntity trailer, 0, -1.6, 0 ;main loop Repeat ;move cab If KeyDown(205) Then TurnEntity cab, 0, 0, -1 If KeyDown(203) Then TurnEntity cab, 0, 0, +1 If KeyDown(200) Then MoveEntity cab, 0, +0.1, 0 If KeyDown(208) Then MoveEntity cab, 0, -0.1, 0 ;align trailer to pivot PointEntity trailer, pivot MoveEntity trailer, 0, 0, EntityDistance(trailer, pivot) - 1 RenderWorld Flip Until KeyHit(1)
;setup graphics Graphics3D 800, 600, 0, 2 SetBuffer BackBuffer() CreateLight() camera = CreateCamera() PositionEntity camera, 0, -8, 2 RotateEntity camera, -90, 0, 0 ;create cab cab = CreateCone() RotateMesh cab, -90, 180, 0 ScaleEntity cab, 0.4, 0.4, 0.4 ;create pivot pivot = CreateSphere(8,cab) ScaleEntity pivot, 0.2, 0.2, 0.2 EntityColor pivot, 0, 255, 0 EntityOrder pivot, -1 ;pivot=CreatePivot(cab) PositionEntity pivot, 0, 0, -1 ;create trailer trailer = CreateCone() RotateMesh trailer, 90, 0, 0 ScaleEntity trailer, 0.39, 0.4, 1 EntityColor trailer, 255, 0, 0 PositionEntity trailer, 0, 0, -2 ;main loop Repeat yw# = AngDist(EntityYaw(cab), EntityYaw(trailer)) ;move cab If KeyDown(203) Then TurnEntity cab, 0, -1, 0 If KeyDown(205) Then TurnEntity cab, 0, +1, 0 If KeyDown(200) Then MoveEntity cab, 0, 0, +0.1 If KeyDown(208) Then MoveEntity cab, 0, 0, -0.1 ;align trailer to pivot PointEntity trailer, pivot MoveEntity trailer, 0, 0, EntityDistance(trailer, pivot) - 1 RenderWorld Text 0, 0, yw Flip Until KeyHit(1) End ;----------------------------------------------------------------------------------------------------- ; AngDist() ;----------------------------------------------------------------------------------------------------- ;returns shortest difference between two angles Function AngDist#(ang1#, ang2#) Local c1# = (ang2 - ang1) Local c2# = (ang2 + 360 - ang1) Local c3# = (ang2 - 360 - ang1) If Abs(c3) < Abs(c1) Then c1 = c3 If Abs(c2) < Abs(c1) Then c1 = c2 Return c1 End Function
;main loop Repeat ;align trailer to pivot PointEntity trailer, pivot MoveEntity trailer, 0, 0, EntityDistance(trailer, pivot) - 1 yw# = AngDist(EntityYaw(cab), EntityYaw(trailer)) If Abs(yw) > 45 Then TurnEntity trailer, 0, -(yw - (45 * Sgn(yw))), 0 PositionEntity trailer, EntityX(pivot, 1), EntityY(pivot, 1), EntityZ(pivot, 1) MoveEntity trailer, 0, 0, EntityDistance(trailer, pivot) - 1 End If ;move cab If KeyDown(203) Then TurnEntity cab, 0, -1, 0 If KeyDown(205) Then TurnEntity cab, 0, +1, 0 If KeyDown(200) Then MoveEntity cab, 0, 0, +0.1 If KeyDown(208) Then MoveEntity cab, 0, 0, -0.1 RenderWorld Text 0, 0, yw Flip Until KeyHit(1)