Help with your scripting

If exists and vertical platform

If exists and vertical platform

Postby epsilonion » 20 Feb 2018, 01:20

I thought I would take a look at a old scene I made in gen1..

1. I have 2 scripts one that spawns a barrel and when it hits the death trigger box it deletes it but it only spawns 2 barrels then stops running the script.

Barrel Spawn Script
Code: Select all
obj = 0;
spawnID = 0;                                 -- Set Exist to 0 to spawn 1st barrel

function onInit(objID)
   sky.lprint("LUA: Script Active!");
   obj = objID;
   x,y,z = entity.getWorldPosition( obj );            --Get the world position of the barrel spawn point
end

function onUpdate(timeDelta)

   if( entity.exist(spawnID) == 0 ) then             -- check that barrel doesnt exist
      spawnID = entity.spawnPreset("Barrel 05",x,y,z);      -- Spawn the preset barrel05 @ world position of spawn point
      entity.setTag(spawnID,"barrel01");               -- Set the Tag so barrel can be refrenced in other script.
   end

end

--[[ Not Needed once deleted spawnID wont hold any value
function spawnBarrel (value)

   if (value == "0") then
      spawnID = 0;
   end
end
]]--


Death Trigger Script.
Code: Select all
obj = 0;
x,y,z =0;
function onInit(objID)
   sky.lprint("LUA: Script Active!");
   obj = objID;
   playerID = entity.getIDFromTag("player");
   x,y,z = entity.getPosition(entity.getIDFromTag("spawnpoint"));
   y=y+2;
end

-- Updated every frame
function onUpdate(timeDelta)
   
end


function onTrigger_Enter(hitID)
   entname = entity.getTagFromID(hitID)                         --Get the TAG from the ID of the entity that collided with the trigger box
   if(entname == "Player")then                             -- the name of the player entity
      sky.lprint("Player Detected...");                   --Left for debugging
      character.setPosition(hitID,x,y,z);
   end
   
   if(entname == ("barrel01"))then                             -- the name of the player entity
      entity.delete( entity.getIDFromTag("barrel01") );
   --   entity.callFn( obj,  (entity.getIDFromTag("bar_spawn")), spawnBarrel, 0);
   end
   
   if(entname == ("barrel02"))then                             -- the name of the player entity
      entity.delete( entity.getIDFromTag("barrel02") );
   end

end


2. I have a verticle platform that moves up and down, when it hits xx limit then changes direction, it sort of works but the visual is well check out the video below.... it worked in gen1...

Code: Select all
obj = 0;
direction=1.2;
x,y,z =0;
lift1ID = 0;

function onInit(objID)
   obj = objID;
   lift1ID = entity.getIDFromTag("lift1");
   bodyID = physics.getBodyID(lift1ID);
end

function onUpdate(timeDelta)

      x,y,z = entity.getPosition( lift1ID );
      --sky.lprint("Position ok");
      y=y+(direction)*timeDelta;

        if (y > -6.79999) then direction = -2.2; --sky.lprint("lower limit")
      end
      
      if (y < -11.4529) then direction = 2.2; --sky.lprint("higher limit")
      end
      entity.setPosition(lift1ID,x,y,z);
      wx,wy,wz = entity.getWorldPosition( lift1ID );
   
     physics.setPosition(bodyID,wx,wy,wz);
     
end




The main idea I had for this one was to use it as part of a tutorial series for beginners to use to get used to the workflows in skyline, obviously the next scene would be a fps and 3rd scene a 3rd person then top down.. :P
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 818
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: If exists and vertical platform

Postby SolarPortal » 20 Feb 2018, 13:00

Try using a kinematic physics body for the lift and use the
physics.move(); command...

i did do a platform script with dynamic properties but never got the chance to finish it.. will see if i can dig it up at some point :)

As for the 2 barrels...im wondering if the tag name is not being cleared.... would have to check this one out too :)
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3100
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: If exists and vertical platform

Postby epsilonion » 20 Feb 2018, 17:56

its is using kinematic but will try the physics command.. :P
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 818
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: If exists and vertical platform

Postby SolarPortal » 20 Feb 2018, 19:01

If you use physics.setPosition() then collisions will never happen which means it will pass through another physics object.
physics.move() moves the kinematic controller in physics space and takes collision into account.

also, you don't need to use the entity.setPosition as this is done in the physics.move or setPosition() which could be a cause of the jumping also.
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3100
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: If exists and vertical platform

Postby epsilonion » 20 Feb 2018, 19:07

cool thank you ... just wondered what was different in gen2 because it worked perfect in gen 1 lol
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 818
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 2 guests