So no problem. I've been doing some testing anyway just to figure out the problem.
I am using this script that I found here:
https://www.nexusmods.com/legendofgrimrock2/mods/10
Code: Select all
function lowerPlatform()
local y = elevator_platform:getWorldPositionY()
local level = elevator_platform.level
local px = elevator_platform.x
local py = elevator_platform.y
local face = elevator_platform.facing
elevator_ascend_timer.timer:stop() -- Lets not do both at once
y = y - 0.01
-- Each grid cube is 3 units high in worldspace
-- Once we're below the 'lip' that we want the party to be able
-- to cross, we need to change the vertical coordinate of the platform
if y<-0.5 then
elevator_platform:setPosition(px,py,face,-1,level)
elseif y<2.5 then
elevator_platform:setPosition(px,py,face,0,level)
end
if y<-3 then -- Stop the elevator
y=-3
elevator_descend_timer.timer:stop()
end
elevator_platform:setWorldPositionY(y)
end
function raisePlatform()
local y = elevator_platform:getWorldPositionY()
local level = elevator_platform.level
local px = elevator_platform.x
local py = elevator_platform.y
local face = elevator_platform.facing
elevator_descend_timer.timer:stop() -- Lets not do both at once
y = y + 0.01
-- Each grid cube is 3 units high in worldspace
-- Once we're below the 'lip' that we want the party to be able
-- to cross, we need to change the vertical coordinate of the platform
if y>2.5 then
elevator_platform:setPosition(px,py,face,1,level)
elseif y>-0.5 then
elevator_platform:setPosition(px,py,face,0,level)
end
if y>3 then -- Stop the elevator
y=3
elevator_ascend_timer.timer:stop()
end
elevator_platform:setWorldPositionY(y)
-- However, we also have to adjust the position of everything in this square
-- Otherwise things will fall through the platform
-- We might also want to adjust only things near the platform's level
-- so that e.g. you can hide under an elevator tile.
for obj in elevator_platform.map:entitiesAt(px,py) do
if obj.gravity then -- Only move things that would be lifted
if (math.abs(obj:getWorldPositionY()-y)<0.5) then
obj:setWorldPositionY(y+0.01)
end
end
end
end
I have the script connected to 2 timers one for function raisePlatform() and the other for function lowerPlatform(). Each timer is connected to it's own lever. (I'm using levers, he used a button but the effect should be the same.) The idea is you pull the lever and it starts the object moving up or down. In his example he used a Castle Bridge.
For the testing purposes, I've gone ahead and copied everything over like he had with the only exception being that I'm not using a 3 tiered level. It works, until I remove the castle bridge object and add in the movable block object and rename it. The block falls just fine due to the gravity component. (It does take 10 seconds to do so but does so.)
Code: Select all
defineObject{
name = "falling_block",
baseObject = "base_floor_decoration",
components = {
{
class = "Model",
model = "assets/models/env/pushable_block_01.fbx",
},
{
class = "ProjectileCollider",
},
{
class = "Obstacle",
hitSound = "$weapon",
},
{
class = "Gravity",
},
{
class = "DynamicObstacle",
},
{
class = "PushableBlock",
},
{
class = "Clickable",
name = "clickNorth",
offset = vec(0, 1.15, 1.2),
size = vec(1.2, 1.2, 0.1),
maxDistance = 1,
--debugDraw = true,
onClick = function(self)
if party.facing == (self.go.facing+2) % 4 then
self.go.pushableblock:push(party.facing)
end
end,
},
{
class = "Clickable",
name = "clickEast",
offset = vec(1.2, 1.15, 0),
size = vec(0.1, 1.2, 1.2),
maxDistance = 1,
--debugDraw = true,
onClick = function(self)
if party.facing == (self.go.facing+3) % 4 then
self.go.pushableblock:push(party.facing)
end
end,
},
{
class = "Clickable",
name = "clickSouth",
offset = vec(0, 1.15, -1.2),
size = vec(1.2, 1.2, 0.1),
maxDistance = 1,
--debugDraw = true,
onClick = function(self)
if party.facing == self.go.facing then
self.go.pushableblock:push(party.facing)
end
end,
},
{
class = "Clickable",
name = "clickWest",
offset = vec(-1.2, 1.15, 0),
size = vec(0.1, 1.2, 1.2),
maxDistance = 1,
--debugDraw = true,
onClick = function(self)
if party.facing == (self.go.facing+1) % 4 then
self.go.pushableblock:push(party.facing)
end
end,
},
{
class = "Light",
name = "lightNorth",
offset = vec(0,1.2,1.2),
range = 1.2,
color = vec(5,2,2,0.3),
brightness = 2,
fadeOut = 0,
fillLight = true,
},
{
class = "Light",
name = "lightEast",
offset = vec(1.2,1.2,0),
range = 1.2,
color = vec(5,2,2,0.3),
brightness = 2,
fadeOut = 0,
fillLight = true,
},
{
class = "Light",
name = "lightSouth",
offset = vec(0,1.2,-1.2),
range = 1.2,
color = vec(5,2,2,0.3),
brightness = 2,
fadeOut = 0,
fillLight = true,
},
{
class = "Light",
name = "lightWest",
offset = vec(-1.2,1.2,0),
range = 1.2,
color = vec(5,2,2,0.3),
brightness = 2,
fadeOut = 0,
fillLight = true,
},
{
class = "Sound",
sound = "pushable_block_hover",
offset = vec(0, 1.5, 0),
enabled = false,
},
},
editorIcon = 220,
}
When you hit the lever for it to go up. It jumps the first iteration of the raisePlatform() script, but is pulled immediately back down to its base default position, and never moves up. This is with or without the pushable floor tiles active or off. Which is why I was saying it probably has to do with the pushable block itself or the pushable floor tiles.
This is why I was asking if there was a way to script the block itself to move up and down. I also had concerns with what minmay pointed out with the object collider. If I can script the pushable block itself to move up or down. Then I can script a function with a button press or off the monster.die that pushes the block back up as if the player was pushing it.
edit:
Further testing. I thought it may be the gravity component itself, so I added in enabled = true to the gravity component to turn it off and on, then added to the elevator script the argument to turn off gravity ((elevator_platform.gravity:disable() )). The result of this was the same as before. So I tried this with a default pushable block. ((Here's the script for you Pompidom))
Code: Select all
defineObject{
name = "pushable_block",
baseObject = "base_floor_decoration",
components = {
{
class = "Model",
model = "assets/models/env/pushable_block_01.fbx",
},
{
class = "ProjectileCollider",
},
{
class = "Obstacle",
hitSound = "$weapon",
},
{
class = "DynamicObstacle",
},
{
class = "PushableBlock",
},
{
class = "Clickable",
name = "clickNorth",
offset = vec(0, 1.15, 1.2),
size = vec(1.2, 1.2, 0.1),
maxDistance = 1,
--debugDraw = true,
onClick = function(self)
if party.facing == (self.go.facing+2) % 4 then
self.go.pushableblock:push(party.facing)
end
end,
},
{
class = "Clickable",
name = "clickEast",
offset = vec(1.2, 1.15, 0),
size = vec(0.1, 1.2, 1.2),
maxDistance = 1,
--debugDraw = true,
onClick = function(self)
if party.facing == (self.go.facing+3) % 4 then
self.go.pushableblock:push(party.facing)
end
end,
},
{
class = "Clickable",
name = "clickSouth",
offset = vec(0, 1.15, -1.2),
size = vec(1.2, 1.2, 0.1),
maxDistance = 1,
--debugDraw = true,
onClick = function(self)
if party.facing == self.go.facing then
self.go.pushableblock:push(party.facing)
end
end,
},
{
class = "Clickable",
name = "clickWest",
offset = vec(-1.2, 1.15, 0),
size = vec(0.1, 1.2, 1.2),
maxDistance = 1,
--debugDraw = true,
onClick = function(self)
if party.facing == (self.go.facing+1) % 4 then
self.go.pushableblock:push(party.facing)
end
end,
},
{
class = "Light",
name = "lightNorth",
offset = vec(0,1.2,1.2),
range = 1.2,
color = vec(5,2,2,0.3),
brightness = 2,
fadeOut = 0,
fillLight = true,
},
{
class = "Light",
name = "lightEast",
offset = vec(1.2,1.2,0),
range = 1.2,
color = vec(5,2,2,0.3),
brightness = 2,
fadeOut = 0,
fillLight = true,
},
{
class = "Light",
name = "lightSouth",
offset = vec(0,1.2,-1.2),
range = 1.2,
color = vec(5,2,2,0.3),
brightness = 2,
fadeOut = 0,
fillLight = true,
},
{
class = "Light",
name = "lightWest",
offset = vec(-1.2,1.2,0),
range = 1.2,
color = vec(5,2,2,0.3),
brightness = 2,
fadeOut = 0,
fillLight = true,
},
{
class = "Sound",
sound = "pushable_block_hover",
offset = vec(0, 1.5, 0),
enabled = false,
},
},
editorIcon = 220,
}
The block refuses to raise or lower at all. I will continue my testing on this.
As a side note: I did notice that the castle bridge will only raise when the height allows for the characters to move to the floor above it regardless of height setting in the script, but will seem to lower through the floor without stopping until it reaches the lower height value.