Anything to do with physics. Rigid Bodies, Kinematic controllers, vehicles etc.

Set up physics for a door?

Set up physics for a door?

Postby CreativeOcclusion » 22 Oct 2015, 21:08

Is there any info on how to set up the physics for a door...I have the door working, opening and closing...But, the physics body is being left in the doorway when door is open...this makes it where the character cannot go through the doorway...

I have tried every combination of physics on the door...any help would be appreciated....thanks
Thanks, CreativeOcclusion
User avatar
CreativeOcclusion
Skyline Warrior
 
Posts: 366
Joined: 22 Jun 2015, 19:34
Location: Texas

Re: Set up physics for a door?

Postby SolarPortal » 22 Oct 2015, 21:23

I have an idea, just need to test it :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Set up physics for a door?

Postby SolarPortal » 22 Oct 2015, 22:50

Hey, i had a bit of a go and had a pretty successful go at it as well.
It is all possible within one line hehe... well it is simply the code below placed after all movements have occurred.

Code: Select all
physics.setRotation(bodyID, entity.getWorldOrientation(obj));


What i used: I made a door with the pivot in the bottom right corner and added a rigidbody with kinematic physics. I also used the convex mesh hull as it will always surround the mesh correctly and is much easier than the box as it requires an offset.

Added a microscript and programmed a door from it and used the above command to set the kinematic body position.
Here is the full script:

Code: Select all
-- | User Vars
reverse = -1;      -- | Set this to -1 to rotate the door the other way. Set 1 to move positive.
doorSpeed = 150;    -- | Controls how fast the door opens and closes. Its large as it is using timedelta.
openAngle = 90;     -- | This is the maximum angle the door can open. Great for blocked doors.
closeAngle = 0;     -- | This is the close angle. 0 is starting point.

-- | System Vars
opendoor = false;
closedoor = false;
currentAngle = 0;
bodyID = -1;
obj = 0;

function onInit(objID)
   obj = objID;
end

function postInit()
   bodyID = physics.getBodyID(obj);
end

function onKeyDown( key )
   if(key=="f")then
      if(opendoor == true)then
         opendoor = false;
         closedoor = true;
      elseif(opendoor == false)then
         opendoor = true;
         closedoor = false;
      end
   end
   
   if(key=="e")then
      opendoor = false;
      closedoor = true;
   end
end


function onUpdate( timeDelta )
   elapsedTime = timeDelta;
   if(elapsedTime > 0.25)then elapsedTime = 0.25; end
   if(bodyID < 0)then return; end
   
   if(opendoor == true )then
      speed = doorSpeed * elapsedTime;
   
      if(reverse > 0)then
         if(currentAngle < openAngle)then
            entity.turn(obj, 0, speed, 0);
            currentAngle = currentAngle + speed;
         end
      elseif(reverse < 0)then
         if(currentAngle > -openAngle)then
            entity.turn(obj, 0, -speed, 0);
            currentAngle = currentAngle - speed;
         end
      end
      
      updatePhysics();
   end
   
   if(closedoor == true)then
      if(reverse > 0)then
         if(currentAngle > closeAngle)then
            entity.turn(obj, 0, -speed, 0);
            currentAngle = currentAngle - speed;   
         end
      elseif(reverse < 0)then
         if(currentAngle < -closeAngle)then
            entity.turn(obj, 0, speed, 0);
            currentAngle = currentAngle + speed;   
         end
      end
      
      updatePhysics();
   end
end

function updatePhysics()
   physics.setRotation(bodyID, entity.getWorldOrientation(obj));
end


Note: This door mechanic will work on a door that is set at any angle on the Y axis. It means you can rotate the door to any angle and then the door will rotate to max and back again.

I will be releasing a new demo soon which has an opening door and will be converting this script into a dynamic property script for re usability.

Hope this helps :D
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Set up physics for a door?

Postby CreativeOcclusion » 23 Oct 2015, 08:05

This is great...Thanks...At the moment I am working on a sliding door...vertical sliding up...I will keep this code to use at a later date...Sorry for the late reply, I have been working late a lot of the time lately...
Thanks, CreativeOcclusion
User avatar
CreativeOcclusion
Skyline Warrior
 
Posts: 366
Joined: 22 Jun 2015, 19:34
Location: Texas

Re: Set up physics for a door?

Postby CreativeOcclusion » 23 Oct 2015, 08:35

Still having problems with sliding door...
Thanks, CreativeOcclusion
User avatar
CreativeOcclusion
Skyline Warrior
 
Posts: 366
Joined: 22 Jun 2015, 19:34
Location: Texas

Re: Set up physics for a door?

Postby SolarPortal » 23 Oct 2015, 13:14

aah, lol :P i just assumed the door rotated.
I should never judge a door by its hinges lmao :lol:

try using this command then :)

Code: Select all
physics.setPosition(bodyID, entity.getWorldPosition(obj));


Note: The physics pivot and the entity pivot must match. If not add the offset required in a vec3 and pass it like this.

Code: Select all
offset = newType.vec3( 0, 1, 0 );
pos = newType.vec3( entity.getWorldPosition(obj) );
pos.x = pos.x + offset.x;
pos.y = pos.x + offset.y;
pos.z = pos.x + offset.z;
physics.setPosition(bodyID, pos.x, pos.y, pos.z);


I hope this helps :D
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Set up physics for a door?

Postby CreativeOcclusion » 23 Oct 2015, 20:35

Thanks for the help...We got it working....
Thanks, CreativeOcclusion
User avatar
CreativeOcclusion
Skyline Warrior
 
Posts: 366
Joined: 22 Jun 2015, 19:34
Location: Texas

Re: Set up physics for a door?

Postby SolarPortal » 23 Oct 2015, 20:43

Good news :)

I will release the demo of the rotating door once complete :D
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Set up physics for a door?

Postby SolarPortal » 02 Nov 2015, 14:53

i forgot to make a video to showcase the rotating door, so here it is:

Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Set up physics for a door?

Postby CreativeOcclusion » 02 Nov 2015, 18:45

i forgot to make a video to showcase the rotating door, so here it is:


Thanks...Good job...
Thanks, CreativeOcclusion
User avatar
CreativeOcclusion
Skyline Warrior
 
Posts: 366
Joined: 22 Jun 2015, 19:34
Location: Texas

Re: Set up physics for a door?

Postby TattieBoJangle » 02 Nov 2015, 20:16

Is there an option to have the physics follow the door as it goes around in turn giving the door force sort of thing when I say physics I mean the collision so it pushes the player or an object as it opens closes ;)
Case: CM Storm Trooper CPU: I7 5930k X99 Cooler: Noctua NH-D15 Graphics: Asus GTX 1080 Motherboard: Rampage Extreme V x99 Ram: RipJaws DDR4 3000mhz Storage: x2 SSD Crucial 500GB + x5 2TB Hdd PSU: Evga 1500w OS: Windows 10
User avatar
TattieBoJangle
Community Manager
Community Manager
 
Posts: 858
Joined: 26 Jan 2015, 00:15
Location: United Kingdom
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer
Skill: Great creative

Re: Set up physics for a door?

Postby SolarPortal » 02 Nov 2015, 21:29

if you try and walk into the door while its moving, the character wont be able to go through the door unless the door is coming towards you as the player or if you are standing still. If you follow the door as its opening or closing and catch it up, you won't walk through it.

When i was building it, we already decided that we needed to add this feature, but have not found the time yet :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Set up physics for a door?

Postby TattieBoJangle » 02 Nov 2015, 21:39

Ahh I see no probs i was just wondering if it was possible as would be cool for a few other things I could think of ;)
Case: CM Storm Trooper CPU: I7 5930k X99 Cooler: Noctua NH-D15 Graphics: Asus GTX 1080 Motherboard: Rampage Extreme V x99 Ram: RipJaws DDR4 3000mhz Storage: x2 SSD Crucial 500GB + x5 2TB Hdd PSU: Evga 1500w OS: Windows 10
User avatar
TattieBoJangle
Community Manager
Community Manager
 
Posts: 858
Joined: 26 Jan 2015, 00:15
Location: United Kingdom
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer
Skill: Great creative

Re: Set up physics for a door?

Postby SolarPortal » 02 Nov 2015, 21:44

yeah, this feature is needed so other characters can walk into you and move you. Hit a character with a car and you will want the character to go flying especially with ragdoll lol :P As you say, i am sure there are more :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer


Return to Physics

Who is online

Users browsing this forum: No registered users and 1 guest