#code Posted May 3, 2019 Share Posted May 3, 2019 Hello, it's me again. And I'm trying to make joint: Slider shock absorbers. But something goes wrong, and I can not understand that. Please explain how this works. I need the car to fall to the ground and spin the shock absorbers. Code in RaceCar.lua: Script.TireMass = 20 Script.SpringForce = 1000 function Script:Start() self.Wheels={} self.Wheels[0]=self.entity:FindChild("WheelFL") self.Wheels[1]=self.entity:FindChild("WheelFR") self.Wheels[2]=self.entity:FindChild("WheelRL") self.Wheels[3]=self.entity:FindChild("WheelRR") self.Axes={} for n=0,3 do self.Axes[n]=Pivot:Create() self.Axes[n]:SetPosition(self.Wheels[n]:GetPosition()) self.Axes[n]:SetMass(self.TireMass) end self.Directions={} for n = 0, 1 do self.Directions[n]=Pivot:Create(self.Axes[n]) self.Directions[n]:SetPosition(self.Axes[n]:GetPosition()) end for n=2,3 do self.Wheels[n]:SetParent(self.Axes[n]) end for n=0,1 do self.Wheels[n]:SetParent(self.Directions[n]) end for n=0,3 do pos=self.Axes[n]:GetPosition(true) axe=Vec3(0, 1, 0) self.Amortisseurs={} self.Amortisseurs[n]=Joint:Slider(pos.x, pos.y, pos.z, axe.x,axe.y,axe.z, self.Axes[n], self.entity) self.Amortisseurs[n]:EnableLimits() self.Amortisseurs[n]:SetLimits(-1,1) self.Amortisseurs[n]:SetSpring(self.SpringForce,0.25,5) end end And video: What.mp4 Quote Link to comment Share on other sites More sharing options...
#code Posted May 4, 2019 Author Share Posted May 4, 2019 I change script: Script.TireMass = 5 Script.SpringForce = 1000 function Script:Start() self.Wheels={} self.Wheels[0]=self.entity:FindChild("WheelFL") self.Wheels[1]=self.entity:FindChild("WheelFR") self.Wheels[2]=self.entity:FindChild("WheelRL") self.Wheels[3]=self.entity:FindChild("WheelRR") self.Amortisseurs={} self.Axis={} self.SecondAxis={} for n=0,3 do pos=self.Wheels[n]:GetPosition(true) self.Axis[n]=Pivot:Create(self.entity)-- self.Axis[n]:SetPosition(pos, true) axe=Vec3(0, 1, 0) self.Amortisseurs[n]=Joint:Slider(pos.x, pos.y, pos.z, axe.x,axe.y,axe.z, self.Axis[n], self.entity) self.Amortisseurs[n]:EnableLimits() self.Amortisseurs[n]:SetLimits(-1,1) self.Amortisseurs[n]:SetSpring(self.SpringForce,0.25,5) end self.Volants={} for n=0,1 do axe=Vec3(0, 1, 0) self.SecondAxis[n] = Pivot:Create(self.Axis[n])-- pos=self.Wheels[n]:GetPosition(true) self.SecondAxis[n]:SetPosition(pos, true) self.Volants[n]=Joint:Hinge(pos.x, pos.y, pos.z, axe.x,axe.y,axe.z, self.SecondAxis[n], self.Axis[n]) self.Volants[n]:EnableLimits() self.Volants[n]:SetLimits(-30,30) self.Volants[n]:SetMotorSpeed(200) self.Volants[n]:EnableMotor() self.Volants[n]:SetAngle(0) end for n=2,3 do pos=self.Wheels[n]:GetPosition(true) axe=Vec3(1, 0, 0) self.Volants[n]=Joint:Hinge(pos.x, pos.y, pos.z, axe.x,axe.y,axe.z, self.Wheels[n], self.Axis[n]) self.Volants[n]:EnableLimits() self.Volants[n]:SetLimits(-30,30) self.Volants[n]:SetMotorSpeed(200) self.Volants[n]:EnableMotor() self.Volants[n]:SetAngle(0) end self.ThirdAxis={} for n=0,1 do pos=self.Wheels[n]:GetPosition(true) axe=Vec3(1, 0, 0) self.ThirdAxis[n]=Joint:Hinge(pos.x, pos.y, pos.z, axe.x,axe.y,axe.z, self.Wheels[n], self.SecondAxis[n]) self.ThirdAxis[n]:EnableLimits() self.ThirdAxis[n]:SetLimits(-30,30) self.ThirdAxis[n]:SetMotorSpeed(200) self.ThirdAxis[n]:EnableMotor() self.ThirdAxis[n]:SetAngle(0) end end --[[ function Script:UpdateWorld() end ]] function Script:UpdatePhysics() end --[[ --This can be used to select which objects an entity collides with. This overrides collision types completely. function Script:Overlap(e) return Collision:Collide end ]] --[[ function Script:Collision(entity, position, normal, speed) end ]] --[[ function Script:Draw() end ]] --[[ function Script:DrawEach(camera) end ]] --This function will be called after the world is rendered, before the screen is refreshed. --Use this to perform any 2D drawing you want the entity to display. function Script:PostRender(context) end --[[ --This function will be called when the entity is deleted. function Script:Detach() end ]] --[[ --This function will be called when the last instance of this script is deleted. function Script:Cleanup() end ]] --[[ --This function will be called upon completion of a one-shot animation played with the PlayAnimation() command. function Script:EndAnimation(sequence) end ]] But nothing happens. Запись_2019_05_04_13_23_40_651.mp4 MyCar.rar Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.