Jump to content

How do you make a swinging door swing like a door?


MisterGravity
 Share

Recommended Posts

That may be the dumbest question ever. But seriously, I've been playing with these settings for 30 minutes now! How do you make a door swing like a regular door that's not from the Twilight Zone?

 

tumblr_mzfbvm0d1W1qk5t55o1_400.jpg

I'm sure I'll have a million questions in my quest to master the Leadwerks Engine. Thank you for your patience.

Link to comment
Share on other sites

Tested several times, it don't work and the code can't work with any door as it creates is own Joint :

--Create a motorized slider joint
local position=self.entity:GetPosition(true)+self.offset

 

Instead we should use a script using one or two pivots we would place as child of a door that would say around what points the door rotate. I will try to make teh script.

Stop toying and make games

Link to comment
Share on other sites

I'm pretty sure no one responded to the original request with the exact numbers because no one in the history of Leadwerks has ever gotten a door to swing open like a door in the real world.

  • Upvote 1

I'm sure I'll have a million questions in my quest to master the Leadwerks Engine. Thank you for your patience.

Link to comment
Share on other sites

I agree, nobody uses it.

You can look at Hinge command reference that has a Lua example. It seems to work, i didn't succeed to make a script from it for the door.

But the best way would be to havea door with a pivot as child where the Hinge should be and a script for the door.

 

You should ask to skilled math programmers here :)

Stop toying and make games

Link to comment
Share on other sites

I agree, nobody uses it.

You can look at Hinge command reference that has a Lua example. It seems to work, i didn't succeed to make a script from it for the door.

But the best way would be to havea door with a pivot as child where the Hinge should be and a script for the door.

 

You should ask to skilled math programmers here smile.png

 

I didn't think of using a Hinge, that's a good idea. Take the rest of the day off.happy.png

I'm sure I'll have a million questions in my quest to master the Leadwerks Engine. Thank you for your patience.

Link to comment
Share on other sites

Well, I never made a true swinging door, but I made a revolving door.

 

You're not, by chance, using CSG to make the door are you? From what I can tell, you can't specify where a CSG brush pivots, so it will always rotate around it's centre of mass, causing a revolving door rather than a swinging one. If you attach the script to an imported model with it's pivot properly offset in your 3D software of choice to where you want the door to swing then THAT should work correctly.

 

The only way around CSG not having it's pivot where you want is to place a pivot object in the right place and parent it to that.

Link to comment
Share on other sites

You're not, by chance, using CSG to make the door are you? From what I can tell, you can't specify where a CSG brush pivots, so it will always rotate around it's centre of mass, causing a revolving door rather than a swinging one. If you attach the script to an imported model with it's pivot properly offset in your 3D software of choice to where you want the door to swing then THAT should work correctly.

 

The only way around CSG not having it's pivot where you want is to place a pivot object in the right place and parent it to that.

 

I just drew a door with the brush tool and gave it the swinging door script. Then when that didn't work after a considerable amount of time trying to tweak it, I accepted my failure and made it a revolving door.

I'm sure I'll have a million questions in my quest to master the Leadwerks Engine. Thank you for your patience.

Link to comment
Share on other sites

I just drew a door with the brush tool and gave it the swinging door script. Then when that didn't work after a considerable amount of time trying to tweak it, I accepted my failure and made it a revolving door.

 

Well there you have it, then. It's because the pivot for the brush wasn't where it should be. Either model your door in a 3D package and set the pivot in that, or use a seperate pivot object.

Link to comment
Share on other sites

If you have a joint (which you can place anywhere and make a parent) you should be able move the join to cause the child door to move. I'll see what I can do tonight. This is far from impossible smile.png

 

Just to give you some things to read on a way to do this. Check out http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/joint/jointhinge-r735

 

 

Using this joint is how you'd create a door on anything. CSG or not.

Link to comment
Share on other sites

  • 7 months later...

I know, old post, but I wrote this LUA swinging door script as an alternative to the built in script, and maybe someone else might find it useful.

 

This script does not use a hinge joint, it assumes it's attached to a 3D model door with it's pivot point on the side where a normal hinge would go. Set a [1] on the rotation axis you wish to rotate, adjust the movement speed, the open/close angles, and link to optional open/close sounds. It also assumes your operating the door from the FPSPlayer script.

 

Script.rotationAxis = Vec3(0,1,0) --Vec3 "Rotation Axis"
Script.movementSpeed = 3 --float "Movement Speed"
Script.closeAngle = 0 --int "Close Angle"
Script.openAngle = 135 --int "Open Angle"
Script.closeSound = "" --path "Close Sound"
Script.openSound = "" --path "Open Sound"

rotation = Vec3(0,0,0)
moveDoor = false
openDoor = false
openSnd = nil
closeSnd = nil

function Script:Start()
   if self.openSound ~= "" then
       openSnd = Sound:Load(self.openSound)
   end

   if self.closeSound ~= "" then
       closeSnd = Sound:Load(self.closeSound)
   end
end

--FPSPlayer Use method
function Script:Use()
   if openDoor == true then
       if closeSnd ~= nil then
           closeSnd:Play()
       end
       openDoor = false
   else
       if openSnd ~= nil then
           openSnd:Play()
       end
       openDoor = true
   end
   moveDoor = true
end

function Script:UpdateWorld()
   -- Stop movement if the open/close angles have been reached
   if self.rotationAxis.x == 1 then -- X rotation axis set
       if openDoor == true and self.entity:GetRotation().x >= self.openAngle then
           moveDoor = false
       end
       if openDoor == false and self.entity:GetRotation().x <= self.closeAngle then
           moveDoor = false
       end
   end

   if self.rotationAxis.y == 1 then -- Y rotation axis set
       if openDoor == true and self.entity:GetRotation().y >= self.openAngle then
           moveDoor = false
       end
       if openDoor == false and self.entity:GetRotation().y <= self.closeAngle then
           moveDoor = false
       end
   end

   if self.rotationAxis.z == 1 then -- Z rotation axis set
       if openDoor == true and self.entity:GetRotation().z >= self.openAngle then
           moveDoor = false
       end
       if openDoor == false and self.entity:GetRotation().z <= self.closeAngle then
           moveDoor = false
       end
   end

   -- Move the door towards it's selected position
   if moveDoor == true then
       if openDoor == true then -- Close door    
           if self.rotationAxis.x == 1 then
               rotation.x = rotation.x + (Time:GetSpeed() * self.movementSpeed)
           end
           if self.rotationAxis.y == 1 then
               rotation.y = rotation.y + (Time:GetSpeed() * self.movementSpeed)
           end
           if self.rotationAxis.z == 1 then
               rotation.z = rotation.z + (Time:GetSpeed() * self.movementSpeed)
           end            
       else -- Open door
           if self.rotationAxis.x == 1 then
               rotation.x = rotation.x - (Time:GetSpeed() * self.movementSpeed)
           end
           if self.rotationAxis.y == 1 then
               rotation.y = rotation.y - (Time:GetSpeed() * self.movementSpeed)
           end
           if self.rotationAxis.z == 1 then
               rotation.z = rotation.z - (Time:GetSpeed() * self.movementSpeed)
           end
       end    
       self.entity:SetRotation(rotation)
   end
end

Link to comment
Share on other sites

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.

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.

 Share

×
×
  • Create New...