HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: basic Elevator  (Read 1822 times)

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
basic Elevator
« on: Feb 07, 14, 11:06:43 PM »

Moderate script

This currently only works on the client side. The client will see it, and be able to use it, however  when another player is in the same area, they will not see the player riding on it, but see the player moving as if they were. When you get on it, you will see some lines printing in the console window.

In a test area, add 1 new whitebox, use the cube shape.

In the Properties panel:
set the position to   0,-0.1,-1
set the scale to   2,0.01,2          This sets the size. (strange it's not like the trigger)
set AutoGroundSnap to true

-------------------------------------------------------------------------------------------------------------------------------

click Visibility Tab, select Trigger.      This will let you see any triggers in the area.
click Create Tab, select Trigger.         This will add 1 new trigger to the area.
click Selection Tab, select Trigger.    This will let you target the trigger.

In the Properties panel:
set Name to Elevator.     This is part of the name of the function that gets called.
set Triggerscript to MovingObjects.      This is the name of the script the function is in.
set Enter to true              These are the function types that will get called when the trigger is used.
set Leave to true
set Reside to true
set PlayerSensitive to true.   This is so that the trigger will react to player characters.
set Active to true.    This lets the player use an active trigger.
set period to     0.25     This is the amount of time in seconds before its checked.
set Width to   0.4   Size of the trigger box.
set Depth to    0.4
set Height to   3.5    For player to activate and keep it going they need to be in trigger.
                           (There might be better ways to do this, other than using the height, but this is currently working)

set Position to   0,1.65,-1             This will set the trigger above the whitebox.
------------------------------------------------------------------------------------------------------------------------------

Create a new script (server side)  MovingObjects

Code: [Select]

function Elevator_TriggerEnter( traveler as NodeRef )
  println( "Entered elevator..." )

  where traveler is kindof E_playerCharacter
    account as NodeRef of Class E_playerAccount = traveler.GetMyAccount()
    call client account MovingObjects:ElevatorInit()
  .
.

function Elevator_TriggerReside( traveler as NodeRef )
  println( "Riding elevator..." )

  where traveler is kindof E_playerCharacter
    account as NodeRef of Class E_playerAccount = traveler.GetMyAccount()
    call client account MovingObjects:ElevatorUp()
  .
.

function Elevator_TriggerLeave( traveler as NodeRef )
  println( "left elevator..." )

  where traveler is kindof E_playerCharacter
    account as NodeRef of Class E_playerAccount = traveler.GetMyAccount()
    call client account MovingObjects:ElevatorInit()
  .
.

------------------------------------------------------------------------------------------------------------------------------

Create a new script (client side)  MovingObjects

After copying  the code below, get the IDs of your added GUIs, and put them in to replace the numbers I have in my code. You will need 1 number from each. On the properties panel, look near the bottom.  The GUID is the number you need. Make sure to get the right one in each. The floor is in 3 places in code, and the trigger in 2 places in code.

Code: [Select]

remote function ElevatorInit()
  floor as NodeRef of Class HBNode = 9223372073060021574
  trigger as NodeRef of Class HBNode = 9223372073060021579

  floor["Position"] = "0,-0.1,-1"
  trigger["Position"] = "0,1.65,-1"
.

remote function ElevatorUp()
  floorPos as Vector3 = GetMeshPos(9223372073060021574)    // floor
  triggerPos as Vector3 = GetMeshPos(9223372073060021579)  // trigger
  playerPos as Vector3 = GetMeshPos(GetAccountID())        // player

  if floorPos.y < 3
    floorPos.y = floorPos.y + 0.1
  else
    floorPos.y = -0.1
  .

  SetMeshPos(9223372073060021574, floorPos)    // floor
  playerPos.y = floorPos.y + 0.048
  SetMeshPos(GetAccountID(), playerPos)        // player

  diff as Float = playerPos.y - floorPos.y
  diff = (playerPos.y - floorPos.y)
  println(" difference VecY "+diff)
.

// check for falling from ACCController
public function CheckElevator() as Boolean
  if ($BASECLIENT._GetAreaID() = 1 or $BASECLIENT._GetAreaID() = 93383990054) // not in CCS
    return false
  .
  floorPos as Vector3 = GetMeshPos(9223372073060021574)    // floor
  playerPos as Vector3 = GetMeshPos(GetAccountID())        // player
  diff as Float = playerPos.y - floorPos.y
  if diff < 0.05
    return true
  .
  return false
.

// given ID, get vector3 of Position
function GetMeshPos(Mesh as ID) as Vector3
  node as NodeRef of Class HBNode = Mesh
  val as String = node["Position"]
  val = replacestring(val,"(", "")     // remove ()
  val = replacestring(val,")", "")

  posType as List of String
  SplitBy(val,",",posType)             // make it an array
  Pos as Vector3 = (posType[1],posType[2],posType[3])       // pos of mesh
  return Pos
.

// given ID and Vector3, set the position
function SetMeshPos(Mesh as ID, pos as Vector3)
  node as NodeRef of Class HBNode = Mesh
  node["Position"] = ""+pos.x+","+pos.y+","+pos.z+""
.
 

replace floor 9223372073060021574
replace trigger 9223372073060021579


------------------------------------------------------------------------------------------------------------------------------

In client side script E_ACCControllerClassMethods  (this part needs to add 2 lines of code in the correct position)

in   method _onPostAnimUpdate(elapsed as TimeInterval)

search for  this line:
        if me.HeroEngineACCC_SnapToGround and not (standing or collide or me.HeroEngineACCC_FreeFalling)

underneath it add:
          if not(TMP_AreaTravelClassMethods:CheckElevator()) //<--- check for elevator

down a few lines look for:
            if (me.HeroEngineACCC_State != DEAD)
              println(SYSTEM.HSL.LOCATION + " has determined I should be falling")
              me.setHJOveridePosture( FALLING )
              me.HeroEngineACCC_StateChanged = true
            .

underneath it add:
          .

above:
          SetNodePosition(mychar,finalpos)
        else

This makes an if check before we check for falling. It will be similar to this:
(maybe not exact as we might have some other stuff in there)

Code: [Select]
        if me.HeroEngineACCC_SnapToGround and not (standing or collide or me.HeroEngineACCC_FreeFalling)
          // start falling.  The problem here is if we are transitioning from swim to walk, this triggers erroneously.

          //          println("Started falling from " + finalpos + " on frame " + GetFrameNumber())
          if not(TMP_AreaTravelClassMethods:CheckElevator())        //<--- check for elevator
            if not(me.HeroEngineACCC_FreeFalling)
              me.HeroEngineACCC_FreeFalling = true
            .
            me.HeroEngineACCC_ImpulseVector = charpos - me.HeroEngineACCC_PreAnimPosition
            if (elapsed.inSeconds > 0)
              me.HeroEngineACCC_ImpulseVector.y = 0.0
              me.HeroEngineACCC_ImpulseVector = me.HeroEngineACCC_ImpulseVector / elapsed.inSeconds
            else
              me.HeroEngineACCC_ImpulseVector = "(0,0,0)"
            .
            if (me.HeroEngineACCC_State != DEAD)
              println(SYSTEM.HSL.LOCATION + " has determined I should be falling")
              me.setHJOveridePosture( FALLING )
              me.HeroEngineACCC_StateChanged = true
            .
          .
          SetNodePosition(mychar,finalpos)
        else

Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

Prometheus2012

  • General Accounts
  • *
  • Posts: 664
    • View Profile
    • Exile-Online
Re: basic Elevator
« Reply #1 on: Feb 09, 14, 02:10:05 PM »

Ah you gotta love the non replication of physics from player to player.