file MPs that follow the marble

  • whirligig
  • whirligig's Avatar Topic Author
  • Offline
  • Professional Marbler
  • Professional Marbler
  • Posts: 444
  • Thank you received: 261
14 Jun 2013 20:51 - 29 Aug 2017 02:50 #1
USAGE:

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.

INSTALLATION:

Copy this code into pathedInteriors.cs:

Code:
Code:
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: Doomblah
Time to create page: 0.867 seconds
We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.