Moving Platforms

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Moving Platforms

Post by bumbaclad »

Hey everyone,
I've been using the forums around here for a bit to help guide me with the editor and thought I'd return the favor and share my moving platforms code with y'all.
These platforms will carry the player on the x,y, and z axis.

Here is a link to my mod forEverQuest:A Link to the Past. http://steamcommunity.com/sharedfiles/f ... =616038736

Here is the steps to implement moving platforms, like the ones I used inside Ak'Anon, into your own dungeons...

First create a new mod then create the timer by pasting this code into init.lua inside the Dungeons\'your mod here'\mod_assets\scripts. This will act as your portal into the engine.

Code: Select all

----------------------------------------------------------------
-----------------------------------------------------------Party
defineObject{
name = "party",
baseObject = "party",
components = 
{
----------------------------------
-----------------------------Timer
{
class = "Timer",
timerInterval = 0.001,
triggerOnStart = true,
onActivate = function(self)
gameLoop.script:run()
end
},
}
}

Create a script inside the editor named gameLoop and paste this code. Use the gameLoop run() to access your scripts that will run your platforms.

Code: Select all

function run()
level1Platforms.script.run()
end

Create a script inside the editor named level1Platform. Paste this code into it; you will never need to touch it again until you copy it for another level.

Code: Select all

init = {}
X = {}
c = {}
es = {}
switch = {}
counter = {}
for int = 1, 99 do --99 possible elevators
init[int] = false
X[int] = 0
counter[int] = 0
c[int] = 1
es[int] = false
switch[int] = false
end
----------------------------------------------------------------
----------------------------------------------------------------
function runV(entity,x,y,u,d,l,i,e,f) --entity,X,Y,U,D,L,I,E
if party.x == x and party.y == y then
if party.elevation < d then
switch[i] = false
end
else
switch[i] = false
end
counter[i] = counter[i] + 1
if counter[i] == c[i] then
counter[i] = 0
c[i] = 1
if es[i] == false then e=e+ 1 else e=e-1 end
sete = true
setp=false
---------------------party
if party.x == x and party.y == y then
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 then
if e < 30 and party.elevation == -3 
or e < 60 and e > 30 and party.elevation == -2 
or e < 90 and e > 60 and party.elevation == -1 
or e < 120 and e > 90 and party.elevation == 0  
or e < 150 and e > 120 and party.elevation == 1 
or e < 180 and e > 150 and party.elevation == 2 
or e < 210 and e > 180 and party.elevation == 3 
or e < 250 and e > 210 and party.elevation == 4 
or e < 280 and e > 250 and party.elevation == 5 
or e < 310 and e > 280 and party.elevation == 6 
or switch[i] == true then
switch[i] = true
setp=true
if e == 0 then
party:setPosition(x,y,party.facing,-3,l) 
setp =false
end
if e == 30 then 
party:setPosition(x,y,party.facing,-2,l)
setp = false
end
if e == 60 then 
party:setPosition(x,y,party.facing,-1,l)
setp = false
end
if e == 90 then
party:setPosition(x,y,party.facing,0,l)
setp = false
end
if e == 120 then
party:setPosition(x,y,party.facing,1,l)
setp = false
end
if e == 150 then
party:setPosition(x,y,party.facing,2,l)
setp = false
end
if e == 180 then
party:setPosition(x,y,party.facing,3,l)
setp = false
end
if e == 210 then
party:setPosition(x,y,party.facing,4,l)
setp = false
end
if e == 240 then
party:setPosition(x,y,party.facing,5,l)
setp = false
end
if e == 270 then
party:setPosition(x,y,party.facing,6,l)
setp = false
end
if setp == true then party:setWorldPosition(x*3+1.5,-9+e/10,(31-y)*3+1.5,0) end
end
end 
end 
---------------elevator
if e == 0 then 
if u == -3 then es[i] = true end 
if d == -3 then es[i] = false end
entity:setPosition(x,y,0,-3,l)
if d == -3 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 30 then 
if u == -2 then es[i] = true end
if d == -2 then es[i] = false end
entity:setPosition(x,y,0,-2,l) 
if d == -2 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end 
c[i] = 50
sete = false
end
if e == 60 then 
if u == -1 then es[i] = true end
if d == -1 then es[i] = false end
entity:setPosition(x,y,0,-1,l)
if d == -1 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end 
c[i] = 50
sete = false
end
if e == 90 then
if u == 0 then es[i] = true end
if d == 0 then es[i] = false end
entity:setPosition(x,y,0,0,l)
if d == 0 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end 
c[i] = 50
sete = false
end
if e == 120 then
if u == 1 then es[i] = true end
if d == 1 then es[i] = false end
entity:setPosition(x,y,0,1,l)
if d == 1 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end 
c[i] = 50
sete = false
end
if e == 150 then
if u == 2 then es[i] = true end
if d == 2 then es[i] = false end
entity:setPosition(x,y,0,2,l)
if d == 2 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 180 then
if u == 3 then es[i] = true end
if d == 3 then es[i] = false end
entity:setPosition(x,y,0,3,l)
if d == 3 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 210 then
if u == 4 then es[i] = true end
if d == 4 then es[i] = false end
entity:setPosition(x,y,0,4,l)
if d == 4 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 240 then
if u == 5 then es[i] = true end
if d == 5 then es[i] = false end
entity:setPosition(x,y,0,5,l)
if d == 5 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end
c[i] = 50
sete = false
end
if e == 270 then
if u == 6 then es[i] = true end
if d == 6 then es[i] = false end
entity:setPosition(x,y,0,6,l)
if d == 6 and f == true then entity:setWorldPosition(x*3+1.5,-8.75+e/10,(31-y)*3+1.5,0) end 
c[i] = 50
sete = false
end
if sete == true then entity:setWorldPosition(x*3+1.5,-9+e/10,(31-y)*3+1.5,0) end 
end
return e
end
----------------------------------------------------------------
----------------------------------------------------------------
function runX(entity,x,y,u,d,h,l,i,e) --entity,X,Y,U,D,H,L,I,E
initlize(entity,i,x,y,h,l)
counter[i] = counter[i] + 1
if counter[i] == c[i] then
counter[i] = 0
c[i] = 1
if es[i] == false then e=e+ 1 else e=e-1 end
setp=false
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 and party.y == entity.y and party.x == entity.x then setp = true end 
---------------elevator
if e == 0 or e/30 == 1 or e/30 == 2 or e/30 == 3 or e/30 == 4 or e/30 == 5 or e/30 == 6 or e/30 == 7 or e/30 == 8 or e/30 == 9
or e/30 == 10 or e/30 == 11 or e/30 == 12 or e/30 == 13 or e/30 == 14 or e/30 == 15 or e/30 == 16 or e/30 == 17 or e/30 == 18 
or e/30 == 19 or e/30 == 20 or e/30 == 21 or e/30 == 22 or e/30 == 23 or e/30 == 24 or e/30 == 25 or e/30 == 26 or e/30 == 27
or e/30 == 28 or e/30 == 29 or e/30 == 30 or e/30 == 31 then
if u == e/30 then es[i] = false c[i] = 50 end 
if d == e/30 then es[i] = true c[i] = 50 end
end
entity:setWorldPosition(e/10+1.5,h*3,(31-y)*3+1.5,0)
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 and party.y == entity.y and party.x == entity.x or setp == true then party:setWorldPosition(e/10+1.5,h*3,(31-y)*3+1.5,0) end
end
return e
end
----------------------------------------------------------------
----------------------------------------------------------------
function runY(entity,x,y,u,d,h,l,i,e) --entity,X,Y,U,D,H,L,I,E
initlize(entity,i,x,y,h,l)
counter[i] = counter[i] + 1
if counter[i] == c[i] then
counter[i] = 0
c[i] = 1
if es[i] == false then e=e- 1 else e=e+1 end
setp=false
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 and party.y == entity.y and party.x == entity.x then setp = true end 
---------------elevator
if e == 0 or e/30 == 1 or e/30 == 2 or e/30 == 3 or e/30 == 4 or e/30 == 5 or e/30 == 6 or e/30 == 7 or e/30 == 8 or e/30 == 9
or e/30 == 10 or e/30 == 11 or e/30 == 12 or e/30 == 13 or e/30 == 14 or e/30 == 15 or e/30 == 16 or e/30 == 17 or e/30 == 18 
or e/30 == 19 or e/30 == 20 or e/30 == 21 or e/30 == 22 or e/30 == 23 or e/30 == 24 or e/30 == 25 or e/30 == 26 or e/30 == 27
or e/30 == 28 or e/30 == 29 or e/30 == 30 or e/30 == 31 then
if u == e/30 then es[i] = true c[i] = 50 end 
if d == e/30 then es[i] = false c[i] = 50 end
end
entity:setWorldPosition(x*3+1.5,h*3,(31-e/30)*3+1.5,0)
if party.elevation >= entity.elevation and party.elevation < entity.elevation + 1 and party.x == entity.x and party.y == entity.y or setp == true then party:setWorldPosition(x*3+1.5,h*3,(31-e/30)*3+1.5,0) end 
end
return e
end
----------------------------------------------------------------
----------------------------------------------------------------
function elevatorswitch(i)
es[i] = true
end
----------------------------------------------------------------
----------------------------------------------------------------
function initlize(entity,i,x,y,h,l)
if init[i] == false then
init[i] = true
entity:setPosition(x,y,0,h,l) 
end
end

Create a platform and name it but make sure to follow it by a number to keep things in order because we will be using it to make our call to the platforms script. This platform can be any object you want but I would recommend a floor or more specifically a magic bridge; since I allowed for it to go through the player when running down. In this example we call them platform1,platform2,platform3.


Create another script named level1Platforms and paste this code into it. This script is where we will initialize and run our platforms.
All spaces are divisions of 30 to create a fluent motion. When initializing vertical runs -3 to 6, -3 being 0 hence -2 would be 30. By initializing it at 30*3 we tell it to start at position 0 on the z axis.
The x and y axis is simply the starting number multiplied by 30.
Next step would only need to be done to reverse the direction that the platform is initially running.
The final step is the call that moves the platforms. Our initializing variable is what keeps track of this. Pass the platform's ID, the platform's starting x, platform's starting y, etc...

Code: Select all

switch = false --initalize switch
--------------------------------------------------
---------------------------------------- initalize
e = {} 
for i = 1, 99 do --1-99 possible elevators
e[i] = 0 
end
e[1] = 30*3 --up/down platform. 0 = -3, every 1 elevation takes +30  
e[2] = 30*14
e[3] = 15*30
---------------------------------------------
----------------------------------------- run
function run()
----------------------------------------- run initalize switch
if switch == false then
switch = true
--start in reverse X changes from ---> to <---   and Y changes from ^ to v
level1Platform.script.elevatorswitch(3) --switch starting direction
end
----------------------------------------- run platforms
--PlatformCounter = platform.script.runV(Entity.id,PositionX,PositionY,UpMax,DownMax,Entity.Level,instance,PlatformCounter,Is there a floor on DownMax true or false)
--PlatformCounter = platform.script.runX(Entity.id,PositionX,PositionY,LeftMax,RightMax,Height,Entity.Level,instance,PlatformCounter)
--PlatformCounter = platform.script.runY(Entity.id,PositionX,PositionY,UpMax,DownMax,Height,Entity.Level,instance,PlatformCounter)
e[1] = level1Platform.script.runV(platform1,15,16,1,0,1,1,e[1],true)
e[2] = level1Platform.script.runX(platform2,14,15,14,15,1,1,2,e[2])
e[3] = level1Platform.script.runY(platform3,16,15,15,16,1,1,3,e[3])
end

You would simply repeat this process on different levels using all unique IDs for the scripts and the platforms.
gameLoop --> level1Platforms --> level1Platform
gameLoop --> level2Platforms --> level2Platform


If you have any questions feel free to ask. I have a sample program of this built but no way to distribute atm.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Moving Platforms

Post by minmay »

This is rather convoluted, wastes a lot of savegame space, and doesn't scale correctly with framerate or work with items...you might be interested in my old script for moving objects (it's had many updates since then but I'm too lazy to explain it again right now).
For example, if you want to move a platform 3 squares (9 meters) up, you just call:

Code: Select all

gobj.script.moveObjectDistance(platform1,{dy=9,vy=2})
All you need to do is add the functionality to move the party/monsters/items along with the platform if they are on top of it.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Re: Moving Platforms

Post by bumbaclad »

minmay wrote:This is rather convoluted, wastes a lot of savegame space, and doesn't scale correctly with framerate or work with items...you might be interested in my old script for moving objects (it's had many updates since then but I'm too lazy to explain it again right now).
For example, if you want to move a platform 3 squares (9 meters) up, you just call:

Code: Select all

gobj.script.moveObjectDistance(platform1,{dy=9,vy=2})
All you need to do is add the functionality to move the party/monsters/items along with the platform if they are on top of it.
My script moves the player with the platform. It really only takes 1 call. So thought it might be easy for people to use.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Moving Platforms

Post by minmay »

Being easy to use doesn't mean anything if it doesn't work properly. Your script moves the party and the platform, but it doesn't move either one correctly unless the game is running at exactly 30 FPS. This is rather unlikely. It is also restricted to a narrow range of elevations and specific number of platforms, when there is no reason to have either restriction.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Moving Platforms

Post by minmay »

Here is a version of my script specifically for vertically moving platforms (all the rotation stuff etc. is removed). A vertically moving platform will carry the party, monsters, and items with it, if any are on top of it. It will move smoothly and with the correct speed at all framerates. The interface is unchanged, so look at my previous posts for how to use it.
You can still use it to move objects in other directions, of course. It will not carry the party, monsters, or items horizontally, as that would actually introduce some serious problems.

Code: Select all

X = 1
Y = 2
Z = 3
W = 4

-- Table of moving GameObjects and corresponding data.
gameObjects = {}

-- Translate a game object's world position.
-- TODO: call callbacks in correct order.
function translate(gobj, x, y, z)
	local pos = gobj:getWorldPosition()
	local gid = gobj.id
	local gData = gameObjects[gid]
	local nx = pos[X]+(x or 0)
	local ny = pos[Y]+(y or 0)
	local nz = pos[Z]+(z or 0)
	if gData then
		local e = gData.endpoints
		local v = gData.velocities
		local c = gData.callbacks
		local callx = false
		local cally = false
		local callz = false
		if e then
			-- reaching an endpoint; velocityCleanup will handle the rest
			if e[X] and ((pos[X] <= e[X] and e[X] <= nx) or (pos[X] >= e[X] and e[X] >= nx)) then
				nx = e[X]
				if v then
					v[X] = nil
					if c and c[X] then
						callx = true
					end
				end
			end
			if e[Y] and ((pos[Y] <= e[Y] and e[Y] <= ny) or (pos[Y] >= e[Y] and e[Y] >= ny)) then
				ny = e[Y]
				if v then
					v[Y] = nil
					if c and c[Y] then
						cally = true
					end
				end
			end
			if e[Z] and ((pos[Z] <= e[Z] and e[Z] <= nz) or (pos[Z] >= e[Z] and e[Z] >= nz)) then
				nz = e[Z]
				if v then
					v[Z] = nil
					if c and c[Z] then
						callz = true
					end
				end
			end
		end
		local newWpos = vec(nx,ny,nz,pos[4])
		local nmx,nmy = gobj.map:worldToMap(newWpos)
		local nme = math.floor(ny/gobj.map:getModuleHeight()+1.35)
		if gobj ~= party and (nmx ~= gobj.x or nmy ~= gobj.y or nme ~= gobj.elevation) then gobj:setPosition(nmx,nmy,gobj.facing,nme,gobj.level) end
		gobj:setWorldPosition(newWpos)
		if callx then
			c[X][1](gobj,c[X][2]) -- call callback with args
			c[X] = nil
		end
		if cally then
			c[Y][1](gobj,c[Y][2]) -- call callback with args
			c[Y] = nil
		end
		if callz then
			c[Z][1](gobj,c[Z][2]) -- call callback with args
			c[Z] = nil
		end
	else	-- if we dont have to worry about endpoints or callbacks, the code is somewhat shorter.
		local newWpos = vec(nx,ny,nz,pos[4])
		local nmx,nmz = gobj.map:worldToMap(newWpos)
		if gobj ~= party then gobj:setPosition(nmx,nmz,gobj.facing,math.floor(ny/gobj.map:getModuleHeight()+1.35),gobj.level) end
		gobj:setWorldPosition(newWpos)
	end
end

-- Update moving objects. Should be called once per frame.
function update()
	local dtime = Time.deltaTime()
	for gobjId,data in pairs(gameObjects) do
		local d = {[X]=0,[Y]=0,[Z]=0}
		local ad = {[X]=nil,[Y]=nil,[Z]=nil}
		local v = data.velocities
		local a = data.accelerations
		for dim = X, Z do
			if v and v[dim] then
				if a and a[dim] then
					-- In case you failed both physics and calculus, this formula will
					-- only work for constant acceleration.
					d[dim] = (v[dim]+0.5*a[dim]*dtime)*dtime
					v[dim] = v[dim]+a[dim]*dtime
				else
					d[dim] = v[dim]*dtime
				end
			end
		end
		if v then
			local obj = findEntity(gobjId)
			local oldY = obj:getWorldPosition()[2]
			translate(obj,d[X],d[Y],d[Z]) 
			if d[Y] and d[Y] ~= 0 and obj.platform and obj.platform:isEnabled() then
				for e in obj.map:entitiesAt(obj.x,obj.y) do
					if (e.gravity or e.item) and math.abs(e:getWorldPosition()[2]-oldY) < e.map:getModuleHeight()/2 then
						e:setWorldPosition(obj:getWorldPosition())
					end
				end
			end
		end
		velocityCleanup(gobjId)
	end
end

-- Set velocity of an object. x/y/z can be nil to leave alone.
function setVelocity(gobj,x,y,z)
	local gobjId = gobj.id
	if not gameObjects[gobjId] then gameObjects[gobjId] = {} end
	local gData = gameObjects[gobjId]
	if not gData.velocities then
		local hasX = x and x ~= 0
		local hasY = y and y ~= 0
		local hasZ = z and z ~= 0
		if hasX or hasY or hasZ then
			gData.velocities = {
				[X]=hasX and x or nil,
				[Y]=hasY and y or nil,
				[Z]=hasZ and z or nil
				}
		end
	else
		gData.velocities[X] = x
		gData.velocities[Y] = y
		gData.velocities[Z] = z
		velocityCleanup(gobjId)
	end
end

-- Modify velocity of an object. x/y/z can be 0 to leave alone.
function modifyVelocity(gobj,x,y,z)
	local gobjId = gobj.id
	if not gameObjects[gobjId] then gameObjects[gobjId] = {} end
	local gData = gameObjects[gobjId]
	if not gData.velocities then
		local hasX = x ~= 0
		local hasY = y ~= 0
		local hasZ = z ~= 0
		if hasX or hasY or hasZ then
			gData.velocities = {
				[X]=hasX and x or nil,
				[Y]=hasY and y or nil,
				[Z]=hasZ and z or nil
				}
		end
	else
		gData.velocities[X] = (gData.velocities[X] or 0)+x
		gData.velocities[Y] = (gData.velocities[Y] or 0)+y
		gData.velocities[Z] = (gData.velocities[Z] or 0)+z
		velocityCleanup(gobjId)
	end
end

-- Move an object a certain distance on each axis with specified velocities,
-- canceling any existing movement *and canceling existing callbacks without calling them*.
-- gobj: object to move
-- move: table with info about how to move the object. Supports the following fields:
--   dx, dy, dz: distance to move each axis (can be nil)
--   vx, vy, vz: velocity to move each axis (sign should match corresponding distance)
--   callbackx, callbacky, callbackz: functions to call when finished moving on axis (can be nil), first argument passed will be the object
--   callbackxargs, callbackyargs, callbackzargs: additional arguments to pass to callbacks (can be nil)
--   callbackpos: function to call when object's map position changes (can be nil), i.e. it crosses a tile boundary, first argument passed will be the object,
--                then the object's *previous* x,y,elevation as the second, third, and fourth arguments.
--   callbackposargs: additional arguments to pass to callbackpos (can be nil)
function moveObjectDistance(gobj,move)
	local gobjId = gobj.id
	setVelocity(gobj,move.vx,move.vy,move.vz)
	setEndpointsDelta(gobj,move.dx,move.dy,move.dz)
	gameObjects[gobjId].accelerations = nil
	if (move.dx and move.callbackx) or (move.dy and move.callbacky) or (move.dz and move.callbackz) or (move.callbackpos) then
		gameObjects[gobjId].callbacks = {[X] = {move.callbackx,move.callbackxargs}, [Y] = {move.callbacky,move.callbackyargs}, [Z] = {move.callbackz,move.callbackzargs}, ["callbackpos"] = {move.callbackpos,move.callbackposargs}}
	else
		gameObjects[gobjId].callbacks = nil -- clear existing
	end
end

-- Set the endpoints of an object relative to its current position. Cancels
-- existing endpoints.
function setEndpointsDelta(gobj,dx,dy,dz)
	local pos = gobj:getWorldPosition()
	local points = {
		[X] = (dx and dx ~= 0 and pos[X]+dx) or nil,
		[Y] = (dy and dy ~= 0 and pos[Y]+dy) or nil,
		[Z] = (dz and dz ~= 0 and pos[Z]+dz) or nil
		}
	if not gameObjects[gobj.id] then
		gameObjects[gobj.id] = {endpoints = points}
	else
		gameObjects[gobj.id].endpoints = points
	end
end

-- remove 0 velocities and corresponding endpoints
-- if channel has no or 0 velocity and no acceleration, will be removed
-- if all channels removed, object is freed
function velocityCleanup(gobjId)
	local gData = gameObjects[gobjId]
	if gData and findEntity(gobjId) then
		local v = gData.velocities
		local a = gData.accelerations
		if v and not a then
			local e = gData.endpoints
			for i = X, Z do
				if (not v[i]) or v[i] == 0 then
					v[i] = nil
					if e then e[i] = nil end
				end
			end
			if not (v[X] or v[Y] or v[Z]) then
				gData.velocities = nil
				gameObjects[gobjId] = nil
			end
		end
	else
		gameObjects[gobjId] = nil
	end
end
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Re: Moving Platforms

Post by bumbaclad »

minmay wrote:Here is a version of my script specifically for vertically moving platforms (all the rotation stuff etc. is removed). A vertically moving platform will carry the party, monsters, and items with it, if any are on top of it. It will move smoothly and with the correct speed at all framerates. The interface is unchanged, so look at my previous posts for how to use it.
You can still use it to move objects in other directions, of course. It will not carry the party, monsters, or items horizontally, as that would actually introduce some serious problems.
Mine does move vertical and horizontal with no serious problems so please try it before knocking it, buddy.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Moving Platforms

Post by minmay »

It doesn't, which I have explained twice. But I guess you aren't interested in fixing it, so I'll leave it at that.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Re: Moving Platforms

Post by bumbaclad »

minmay wrote:It doesn't, which I have explained twice. But I guess you aren't interested in fixing it, so I'll leave it at that.

You only complain about my use of the timer so maybe if you want that fixed give me some sort of solution that dosent involve using your script over mine as you have been insisting while at the same time admitting that yours can not move horizontally. Mine does move vertically and horizontally and I have not seen any major issues. So if someone wants to use it then try it out and don't let this guy put you off.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Moving Platforms

Post by minmay »

Time.deltaTime() to get the time elapsed since the previous frame. Use that to scale your movement and stop at an endpoint, then you can get rid of the huge lookup tables and or blocks.

Your approach for horizontal movement does not work. Consider what happens when the party does any of the following while on the platform:
- moves
- turns
- uses free-look
- makes a melee or firearm attack
- creates a projectile
- casts a burst spell
- drops an item

Dealing with these is much more complicated than a couple of GameObject:setPosition() and GameObject:setWorldPosition() calls. I appreciate what you're trying to do here, but it really needs more time and thought.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
bumbaclad
Posts: 12
Joined: Thu Feb 04, 2016 11:59 pm

Re: Moving Platforms

Post by bumbaclad »

Alright I'll give that a whirl. I have not had any of the problems with the horizontal movement you speak of. You actually speaking from using mine or predisposition?
Post Reply