Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Script.enabled=true--bool "Enabled"
- Script.openstate=false--bool "Start Open"
- Script.distance=Vec3(0,0,0)--Vec3 "Distance"
- Script.movespeed=1--float "Move speed" 0,100,3
- function Script:Start()
- self.rot =1
- self.stopped = true
- self.currentposition = nil
- self.doorstatus = self.openstate
- self.destination = Vec3(0,0,0)
- self.startingposition = self.entity:GetPosition()
- self.startingrotation = self.entity:GetRotation()
- self.omega = self.entity:GetOmega(true)
- self.destination.x = self.startingposition.x+self.distance.x
- self.destination.y = self.startingposition.y+self.distance.y
- self.destination.z = self.startingposition.z+self.distance.z
- self.distance1 = self.entity:GetPosition():DistanceToPoint(Vec3(self.destination.x, self.destination.y,self.destination.z))
- self.destinationglobal = Vec3(0,0,0)
- self.startingpositionglobal = self.entity:GetPosition(true)
- self.startingrotationglobal = self.entity:GetRotation(true)
- self.destinationglobal.x = self.startingpositionglobal.x+self.distance.x
- self.destinationglobal.y = self.startingpositionglobal.y+self.distance.y
- self.destinationglobal.z = self.startingpositionglobal.z+self.distance.z
- self.distanceglobal1 = self.entity:GetPosition():DistanceToPoint(Vec3(self.destinationglobal.x, self.destinationglobal.y,self.destinationglobal.z))
- self.entity:SetKeyValue("type","sliding_door")
- if self.openstate == true then
- self:Open()
- self.stopped = true
- self.doorposition = 100
- self:MoveDoor(self.doorposition)
- self.entity:SetMass(0)
- else
- self:Close()
- self.stopped = true
- self.doorposition = 0
- self:MoveDoor(self.doorposition)
- self.entity:SetMass(0)
- end
- end
- function Script:Open() --in
- if self.enabled then
- self.stopped = false
- self.direction =1
- end
- end
- function Script:Close() --in
- if self.enabled then
- self.stopped = false
- self.direction = -1
- end
- end
- function Script:Toggle()--in
- if self.enabled then
- if self.openstate == true then
- self:Close()
- self.openstate = false
- elseif self.openstate == false then
- self:Open()
- self.openstate = true
- end
- self.component:CallOutputs("[Toggled]")
- end
- end
- function Script:UpdatePhysics()
- -- we check if the entity is physically there because if you usegetangle it will have rounding errors.
- if self.enabled then
- if self.stopped == false then
- if self.direction == -1 then
- if self.doorposition > 0 then
- self.doorposition= self.doorposition - (self.movespeed/self.distance1)
- else
- self.component:CallOutputs("[Closed]")
- self.stopped = true
- self.entity:SetMass(0)
- self.entity:SetRotation(self.startingrotation.x,self.startingrotation.y,self.startingrotation.z)
- end
- end
- if self.direction == 1 then
- if self.doorposition < 100 then
- self.doorposition= self.doorposition + (self.movespeed/self.distance1)
- else
- self.component:CallOutputs("[Opened]")
- self.stopped = true
- self.entity:SetMass(0)
- self.entity:SetRotation(self.startingrotation.x,self.startingrotation.y,self.startingrotation.z)
- end
- end
- end
- end
- end
- function Script:UpdateWorld()
- if self.enabled then
- if self.stopped == false then
- self:MoveDoor(self.doorposition)
- end
- end
- end
- function Script:MoveDoor(percent)
- self.entity:SetMass(100000) -- yeah... real life values sorta....
- self.entity:SetPosition(Math:Lerp(self.startingposition.x,self.destination.x,percent/100) , Math:Lerp(self.startingposition.y,self.destination.y,percent/100) , Math:Lerp(self.startingposition.z,self.destination.z,percent/100)) -- allows item to force it's way through solid objects
- self.entity:PhysicsSetPosition(Math:Lerp(self.startingpositionglobal.x,self.destinationglobal.x,percent/100) , Math:Lerp(self.startingpositionglobal.y,self.destinationglobal.y,percent/100) , Math:Lerp(self.startingpositionglobal.z,self.destinationglobal.z,percent/100)) -- causes entity to update its physics so things dont fall through
- self.entity:PhysicsSetPosition(self.entity:GetPosition(true).x,self.entity:GetPosition(true).y,self.entity:GetPosition(true).z,0)
- self.entity:SetRotation(self.startingrotation.x,self.startingrotation.y,self.startingrotation.z)
- self.entity:SetOmega(self.omega)
- 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)
- --[[
- Debug Stuff
- context:SetBlendMode(Blend.Alpha)
- context:SetColor(1,1,1,14)
- context:DrawText(self.entity:GetPosition().x,2,2)
- context:DrawText(self.startingposition.x,2,12)
- context:DrawText(self.destination.x,2,24)
- context:DrawText(self.doorposition,2,36)
- ]]--
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement