file MPs that follow the marble

  • whirligig
  • whirligig's Avatar Topic Author
  • Offline
  • Professional Marbler
  • Professional Marbler
14 Jun 2013 20:51 - 29 Aug 2017 02:50 #1 by whirligig
MPs that follow the marble was created by whirligig

Use this code to create a new type of MP, PathedFollow. This MP should have initialTargetPosition set to 0 and two nodes in its path, which then should move along one dimension. Set smoothing to linear with a relatively short msToNext. Add the following properties to the MP:

dimension: The dimension of movement (0 = x, 1 = y, 2 = z)
initialPos: The coordinate in this dimension of the first node
finalPos: The coordinate in this dimension of the second node
velocity: The difference between these two divided by msToNext, i.e. platform's velocity in TU/ms
offset: The coordinate of the platform's center relative to its defined origin (usually 0 for square MPs, but not always)

The MP will then slide along this dimension to follow the marble. Floor-like MPs can be moved back and forth at will, and wall-like MPs will block you from passing.


Copy this code into pathedInteriors.cs:

datablock PathedInteriorData(PathedFollow)
   foo = bla;
function PathedFollow::onMissionReset(%this,%obj) {
   if (%obj.sch !$= "") cancel(%obj.sch);
   %obj.sch = schedule(10,0,updatePlatform,%obj);
function updatePlatform(%obj) {
   if (!isObject(%obj)) return;
   %targetPos = getWord(LocalClientConnection.player.getTransform(),%obj.dimension)-%obj.offset;
   if (%obj.finalPos > %obj.initialPos && %targetPos < %obj.initialPos) %targetPos = %obj.initialPos;
   else if (%obj.finalPos > %obj.initialPos && %targetPos > %obj.finalPos) %targetPos = %obj.finalPos;
   else if (%obj.finalPos < %obj.initialPos && %targetPos > %obj.initialPos) %targetPos = %obj.initialPos;
   else if (%obj.finalPos < %obj.initialPos && %targetPos < %obj.finalPos) %targetPos = %obj.finalPos;
   if (%obj.finalPos > %obj.initialPos) %obj.setTargetPosition((%targetPos - %obj.initialPos)/%obj.velocity);
   else %obj.setTargetPosition((%obj.initialPos - %targetPos)/%obj.velocity);
   %obj.sch = schedule(10,0,updatePlatform,%obj);
Last edit: 29 Aug 2017 02:50 by whirligig.
The following user(s) said Thank You: NintendoGamer2900

Please Log in or Create an account to join the conversation.

Moderators: AayrlKalle29Regislian