Help with your scripting

Trying to code a lift...Need Help

Trying to code a lift...Need Help

Postby CreativeOcclusion » 08 Nov 2015, 09:33

I am trying to code a lift that goes down if the Y position is greater than a point and goes up if the Y is less than a point...I am modifying some door code that I found in the scripts folder....I am also moving the physics and the trigger to the new position so they can be reused...The code works great going down, but player falls through lift when going up...Here is my code...I would appreciate any help...This code is attached to a Physx Trigger Volume...

Code: Select all
--My Lift Trigger Script------------------------

obj = 0 -- | Define a variable for our object ID
moveDoor = false;
direction = 0;
y=0;

function onInit(objID)
   direction = direction;
   sky.lprint("\nLUA: Lift Trigger Demo: ACTIVATED");
   doorID = entity.getEntityIDFromTag("Lift_1");
   liftID = entity.getEntityIDFromTag("LiftTrigger_1");
   bodyID = physics.getBodyID(doorID);
   liftBodyID = physics.getBodyID(liftID);
      
   --Sound for door opening and closing...---
   sound.setLooped( 0 );
    sound.setVolume( .1 );
    sound.setSoundFile( "idle.wav" );
    sound.setIsStreamed( 0 );
    sound_ID = sound.create2DSound();
end
   --Moving of door up and down
function onUpdate(timeDelta)
   if(moveDoor)then
      x,y,z = entity.getPosition( doorID );
      y=y+(direction)*timeDelta;
      if(y>.7)then moveDoor = false;y=.7;end
      if(y<-3.1)then moveDoor = false;y=-3.1;end      
      entity.setPosition( doorID, x, y, z );
      physics.setPosition(bodyID, entity.getWorldPosition(doorID));
      entity.setPosition( liftID, x, y, z );
      physics.setPosition(liftBodyID, entity.getWorldPosition(liftID));
   end
end


function onTrigger_Enter(hitID)

   objectHit = entity.getEntityName(hitID);
   sky.lprint("LUA: Trigger Event: ENTER Lift!  Object Hit= "..objectHit);
   x,y,z = entity.getPosition( doorID );
   
   
   if(y>.3)then
      direction = -1.2;
   end
   
   if(y<-2.9)then
      direction = 1.2;
   end
   
   sound.play2DSound( sound_ID );
   sky.lprint("LUA: Trigger Event: Direction  The Direction= "..direction);
   moveDoor = true;
end
Thanks, CreativeOcclusion
User avatar
CreativeOcclusion
Skyline Warrior
 
Posts: 366
Joined: 22 Jun 2015, 19:34
Location: Texas

Re: Trying to code a lift...Need Help

Postby SolarPortal » 08 Nov 2015, 12:38

This is the same error when standing still and the door will go through you.

You can detect that the player is on the platform using a trigger or something and then move the characters position up. Use a kinematic body for the platform.

Im not on the dev PC atm, but this is something we have wanted to build for some time.

Some games, don't even allow you to move around in the elevator as it moves as the Y position of the characters are coded to give the correct feel. Look at the original mass effect.

However, we still need to apply a force in the character when something presses against it to move it out of the way instead of going through 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: Trying to code a lift...Need Help

Postby epsilonion » 08 Nov 2015, 19:00

I have done just this before in several engines, the principle of using a sliding door open/close script usually does the trick with the platform been the door and moves xx in the Y direction.

I have also had issues in the past with elevating platforms and the physics... if your stood on the platform and it moves then you should move with it due to the physics been applied to the platform moves with it (not tested this with skyline yet).

The sliding door script usually works like
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Trying to code a lift...Need Help

Postby epsilonion » 08 Nov 2015, 22:36

It seems like the rigid body physics is not following the platform when it moves? maybe? maybe not?


User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Trying to code a lift...Need Help

Postby TattieBoJangle » 08 Nov 2015, 22:40

Yea I believe this is the same as the doors m8
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: Trying to code a lift...Need Help

Postby CreativeOcclusion » 09 Nov 2015, 01:40

It seems like the rigid body physics is not following the platform when it moves? maybe? maybe not?


This section of the code above moves the physics body and the trigger cube and the trigger physics body to the proper location...I have no idea why it just will not work moving up...It works perfect going down....

Code: Select all
      entity.setPosition( doorID, x, y, z );
      physics.setPosition(bodyID, entity.getWorldPosition(doorID));
      entity.setPosition( liftID, x, y, z );
      physics.setPosition(liftBodyID, entity.getWorldPosition(liftID));
Thanks, CreativeOcclusion
User avatar
CreativeOcclusion
Skyline Warrior
 
Posts: 366
Joined: 22 Jun 2015, 19:34
Location: Texas

Re: Trying to code a lift...Need Help

Postby epsilonion » 09 Nov 2015, 02:35

Think a dev should look at this because if you apply physics to an object it should move with said object.

Say a scene where a car comes down the street and hits the player, this should not be over complicated with having to code the ridged body move as well, with every bump in the terrain (road) would have to be coded as well, maybe a off switch for the ridged body to follow or not? just in case someone requires it not to follow in the future?
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Trying to code a lift...Need Help

Postby CreativeOcclusion » 09 Nov 2015, 06:08

Think a dev should look at this because if you apply physics to an object it should move with said object.


I agree...The engine should handle this....If the physics are set for kinematic, then the physics should move with the object....
Thanks, CreativeOcclusion
User avatar
CreativeOcclusion
Skyline Warrior
 
Posts: 366
Joined: 22 Jun 2015, 19:34
Location: Texas

Re: Trying to code a lift...Need Help

Postby SolarPortal » 09 Nov 2015, 12:34

yeah, will take a look this week. We will be fixing all the forum bugs appearing from the past 2 releases that still stand, then w will release a new patch on top :) Think i will make a topic on this :)
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: Trying to code a lift...Need Help

Postby SolarPortal » 10 Nov 2015, 18:14

The characters can be moved by doors and elevators. The doors are quite smooth, but the elevators make the characters shake as you move up, little strange to look at, but its better than falling through the floor.

This will be apart of the next release.
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: Trying to code a lift...Need Help

Postby CreativeOcclusion » 10 Nov 2015, 18:51

The characters can be moved by doors and elevators. The doors are quite smooth, but the elevators make the characters shake as you move up, little strange to look at, but its better than falling through the floor.

This will be apart of the next release.


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


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 5 guests

cron