Sure.
(or rename it if u don't want to overwrite your file).
btw i made a bookshelf with castle walls, with 2 surfaces and clickable components, so i can't stay in same square of object, that's why i used
but seems clickable is not more reachable from any position.
With model and code it would be more clear i guess.
Code: Select all
defineObject{
name = "prova_alcova",
components = {
{
class = "Model",
model = "mod_assets/models/flying_bookshelf.fbx",
offset = vec(0, 4, 0),
staticShadow = true,
},
--[[
{
class = "Occluder",
offset = vec(0, 4, 0),
model = "mod_assets/models/flying_bookshelf_occluder.fbx",
},
]]
{
class = "Particle",
particleSystem = "mine_support_ceiling_lantern",
offset = vec(0, -0.2, 0),
},
{
class = "Light",
offset = vec(0, -0.2, 0),
range = 8,
color = vec(1.1, 0.7, 0.4),
brightness = 10,
castShadow = true,
staticShadows = true,
},
{
class = "Obstacle",
hitSound = "impact_blunt",
},
{
class = "ItemConstrainBox",
name = "cbox1",
size = vec(3.7, 4, 3.7),
offset = vec(0, 2, 0),
-- debugDraw = true,
},
{
class = "ProjectileCollider",
size = vec(3.4, 4, 3.4),
offset = vec(0, 2, 0),
-- debugDraw = true,
},
{
class = "Surface",
name = "alcoveSurface",
offset = vec(0, 0.82, 1.3),
size = vec(1.3, 0.65),
-- debugDraw = true,
onAcceptItem = function(self,item)
local surf = GameMode.tempSurface
GameMode.tempSurface = nil
if surf == 2 then return false end
end,
},
{
class = "Clickable",
name = "alcoveClickable",
offset = vec(0, 0.82+0.4, 1.3),
size = vec(1.3, 0.8, 0.65),
maxDistance = 1,
--frontFacing = true,
-- debugDraw = true,
onClick = function(self)
if getMouseItem() then GameMode.tempSurface = 1 end
end,
},
{
class = "Surface",
name = "bookshelfSurface",
offset = vec(-1.2, 0.55, 0.75),
size = vec(0.4, 0.3),
-- debugDraw = true,
onAcceptItem = function(self,item)
local surf = GameMode.tempSurface
GameMode.tempSurface = nil
if surf == 1 then return false end
end,
},
{
class = "Clickable",
name = "bookshelfClickable",
offset = vec(-1.2, 0.5+0.3, 0.75),
size = vec(0.4, 0.5, 0.3),
maxDistance = 1,
frontFacing = true,
-- debugDraw = true,
onClick = function(self)
if getMouseItem() then GameMode.tempSurface = 2 end
end,
},
{
class = "Timer",
name = "rotationTimer",
timerInterval = 0.0001,
onActivate = function(self)
local deltaAngle = 2.5
local angleIncrement = math.rad(deltaAngle)
local bookshelfPosition = self.go:getWorldPosition()
local bookshelfRotation = self.go:getWorldRotation()
local bookshelfAngle
----- checking angle for bookshelf
if bookshelfRotation.z.x >= 0 then
bookshelfAngle = math.acos(bookshelfRotation.x.x)
elseif bookshelfRotation.z.x <= 0 then
bookshelfAngle = (math.pi-math.acos(bookshelfRotation.x.x)) + math.pi
end
----- calculating new matrix values
bookshelfRotation.x.x = math.cos(bookshelfAngle-angleIncrement)
bookshelfRotation.x.z = -math.sin(bookshelfAngle-angleIncrement)
bookshelfRotation.z.x = math.sin(bookshelfAngle-angleIncrement)
bookshelfRotation.z.z = math.cos(bookshelfAngle-angleIncrement)
----- setting new matrix
self.go:setWorldRotation(bookshelfRotation)
----- items in alcove
for _, i in self.go.alcoveSurface:contents() do
local itemRotation = i.go:getWorldRotation()
local itemRotationAngle
----- checking rotation angle for items in alcove
if itemRotation.z.x >= 0 then
itemRotationAngle = math.acos(itemRotation.x.x)
elseif itemRotation.z.x <= 0 then
itemRotationAngle = (math.pi-math.acos(itemRotation.x.x)) + math.pi
end
----- calculating new matrix values
itemRotation.x.x = math.cos(itemRotationAngle-angleIncrement)
itemRotation.x.z = -math.sin(itemRotationAngle-angleIncrement)
itemRotation.z.x = math.sin(itemRotationAngle-angleIncrement)
itemRotation.z.z = math.cos(itemRotationAngle-angleIncrement)
----- setting new matrix
i.go:setWorldRotation(itemRotation)
----- checking items revolution
local itemPosition = i.go:getWorldPosition()
local deltaY = itemPosition[3]-bookshelfPosition[3]
local deltaX = itemPosition[1]-bookshelfPosition[1]
local revolutionRadius = math.sqrt(math.abs(deltaX)^2 + math.abs(deltaY)^2) -- distance between items and bookshelf center
local itemRevolutionAngle = (math.atan2( deltaY, deltaX) * 180 / math.pi)*-1
----- setting new items position
i.go:setWorldPosition(revolutionRadius*math.cos(math.rad(-itemRevolutionAngle+deltaAngle))+bookshelfPosition[1], 0.82, revolutionRadius*math.sin(math.rad(-itemRevolutionAngle+deltaAngle))+bookshelfPosition[3], 0)
end
----- items in bookshelf
for _, i in self.go.bookshelfSurface:contents() do
local itemRotation = i.go:getWorldRotation()
local itemRotationAngle
----- checking rotation angle for items in bookshelf
if itemRotation.z.x >= 0 then
itemRotationAngle = math.acos(itemRotation.x.x)
elseif itemRotation.z.x <= 0 then
itemRotationAngle = (math.pi-math.acos(itemRotation.x.x)) + math.pi
end
----- calculating new matrix values
itemRotation.x.x = math.cos(itemRotationAngle-angleIncrement)
itemRotation.x.z = -math.sin(itemRotationAngle-angleIncrement)
itemRotation.z.x = math.sin(itemRotationAngle-angleIncrement)
itemRotation.z.z = math.cos(itemRotationAngle-angleIncrement)
----- setting new matrix
i.go:setWorldRotation(itemRotation)
----- checking items revolution
local itemPosition = i.go:getWorldPosition()
local deltaY = itemPosition[3]-bookshelfPosition[3]
local deltaX = itemPosition[1]-bookshelfPosition[1]
local revolutionRadius = math.sqrt(math.abs(deltaX)^2 + math.abs(deltaY)^2) -- distance between items and bookshelf center
local itemRevolutionAngle = (math.atan2( deltaY, deltaX) * 180 / math.pi)*-1
----- setting new items position
i.go:setWorldPosition(revolutionRadius*math.cos(math.rad(-itemRevolutionAngle+deltaAngle))+bookshelfPosition[1], 0.55, revolutionRadius*math.sin(math.rad(-itemRevolutionAngle+deltaAngle))+bookshelfPosition[3], 0)
end
local cleanAngle = math.floor(math.deg(bookshelfAngle))
if cleanAngle == 0 or cleanAngle == 90 or cleanAngle == 180 or cleanAngle == 270 or cleanAngle == 360 then
playSoundAt("bookshelf_rotation", self.go.level, self.go.x, self.go.y)
end
end,
},
{
class = "Controller",
onStart = function(self)
self.go.rotationTimer:start()
end,
onStop = function(self)
self.go.rotationTimer:stop()
end,
onPause = function(self)
self.go.rotationTimer:pause()
end,
},
},
placement = "floor",
editorIcon = 276,
tags = { "obstacle" },
automapTile = "wall"
}