by 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