Jump to content
Slastraf

platform.lua keeps being disabled

Recommended Posts

Hello

My problem is that I have an Pivot which has the platform.lua script attached.

when I test it out and select it to be enabled at the program start, everything works just fine.

The pivot with all the atttached models are moving right where I want them and at the right speed.

 

But when I select it to be disabled at the start of the program, it just keeps locked.

I am pretty sure when you are ingame you cant make it change or just start inside the game.

I tested it inside flowgraph editor with multiple ways : collision, pushbotton (none of them work)

 

It am very confused about that since the most part of the script is in update...() functions.

So how do you can make it change (via flowgraph) ?

Share this post


Link to post

Try creating a collision trigger. In the flowgraph connect "collision" to "enable"

theres the problem. it just doesnt move (when you go make it enable at program start, it is Ok. Thats why I opened the thread

Share this post


Link to post

Does it have mass? And is there a target pivot?

Yes, just checked everything. When I enable this at start it does move.When I am ingame it deosnt as said

Share this post


Link to post

There were some things that were missing from the platform.lua that I have added. It is commented with what I changed.

 

Basically what happened is if you start disabled or disable it in game, The script set the platforms mass to 0. When you enabled it it did not restore the original mass causing it to not move. The fix was to restore the original mass to the entity when enabled AND you have to give it a little push to get it moving again.

 

Script.enabled = true --bool "Enabled"
Script.speed  = 10 --float "Speed"
Script.target = "" --entity "Target waypoint"
Script.originPosition = nil
Script.targetPosition = nil
Script.currentPosition = nil
Script.currentRotation = nil
Script.moving = nil
Script.oldMass = nil
function Script:Start()
self.originalrotation = self.entity:GetRotation()
self.oldMass = self.entity:GetMass()
if self.entity:GetShadowMode()>0 then
 self.entity:SetShadowMode(2)--Light.Dynamic
end
if self.enabled then
 if self.entity:GetMass()==0 then
  Debug:Error("Entity mass must be greater than zero.")
 end
else
 self.entity:SetMass(0) -- !! BEWARE !! this will cause the platform to not work even if you set self.enabled back to true [FIXED later in code: Einlander]
end
self.entity:SetGravityMode(false) 
self.entity:SetCollisionType(Collision.Scene)
if self.target == nil then
 Debug:Error("No target assigned")
end

self:SetTarget(self.target)
end
function Script:SetTarget(newTarget)
self.currentPosition = self.entity:GetPosition()
self.originPosition = self.entity:GetPosition()
self.targetPosition = newTarget:GetPosition()
--self.distance = self.originPosition:DistanceToPoint(self.targetPosition)
self.target = newTarget

local pos = self.entity:GetPosition(true)
local targetpos = self.target:GetPosition(true)
local pin = pos - targetpos
self.distance = pin:Length()
pin = pin:Normalize()

if self.joint then
 self.joint:DisableMotor()
 self.joint:Release()
end
self.joint=Joint:Slider(targetpos.x,targetpos.y,targetpos.z,pin.x,pin.y,pin.z,self.entity,nil)
self.joint:EnableMotor()
self.joint:SetMotorSpeed(self.speed)
self.joint:SetAngle(-self.distance)
end
function Script:Enable()--in
self.enabled = true
self.entity:SetMass(self.oldMass) -- this line was missing [einlander]
self.entity:AddForce(0,0.001,0) -- give it a tiny push to get it moving [einlander]
end
function Script:Disable()--in
self.enabled = false
self.entity:SetMass(0)
end
function Script:UpdatePhysics()
if self.enabled then 
 --Calculate movement
 local currentpos = self.entity:GetPosition(true)
 local targetpos = self.target:GetPosition(true)
 local d = currentpos:DistanceToPoint(targetpos)
 if d<0.1 then
  --When the target has been reached
  --self.entity:PhysicsSetPosition(self.targetPosition.x, self.targetPosition.y, self.targetPosition.z)
  --self.enabled = false
  self.component:CallOutputs("WaypointReached")
  --Check if the target that we have reached also has a target, which is then our new target/waypoint
  if self.target.script.target ~= nil then
   self:SetTarget(self.target.script.target)
  end
 end
else
 --self.entity:PhysicsSetPosition(self.currentPosition.x, self.currentPosition.y, self.currentPosition.z)
 --self.entity:PhysicsSetRotation(self.currentRotation.x, self.currentRotation.y, self.currentRotation.z)
end
end

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...