Trying to make my own simple little “Build your own base to <x>” sort of game just for fun (and to get myself used to working inside of/with Roblox), was wondering how the old games did the ‘r to rotate’ and ‘t to tilt’ thing.
I am currently using what I assume is a fairly naïve approach. For rotations, I am rotating the CFrame’s lookVector
using a map of vectors to vectors. Similarly for tilting, I’m rotating the CFrame’s upVector
.
-- MAPA and MAPB are linked lists. MAPA is the "current" value, MAPB is the "next" value.
local FACING_MAPA = {
Vector3.new(1, 0, 0),
Vector3.new(0, 0, 1),
Vector3.new(-1, 0, 0),
Vector3.new(0, 0, -1),
default = Vector3.new(1, 0, 0)
}
local FACING_MAPB = {
Vector3.new(0, 0, 1),
Vector3.new(-1, 0, 0),
Vector3.new(0, 0, -1),
Vector3.new(1, 0, 0)
}
local UP_MAPA = {
Vector3.new(1, 0, 0),
Vector3.new(0, -1, 0),
Vector3.new(-1, 0, 0),
Vector3.new(0, 1, 0),
default = Vector3.new(0, 1, 0)
}
local UP_MAPB = {
Vector3.new(0, -1, 0),
Vector3.new(-1, 0, 0),
Vector3.new(0, 1, 0),
Vector3.new(1, 0, 0)
}
function module:UpdateFacing() -- called when 'r' is pressed.
for i, v in ipairs(FACING_MAPA) do
if v == self.facingVector then
self.facingVector = FACING_MAPB[i]
return
end
end
self.facingVector = FACING_MAPA.default
end
function module:UpdateUp() -- called when 't' is pressed.
for i, v in ipairs(UP_MAPA) do
if v == self.upVector then
self.upVector = UP_MAPB[i]
return
end
end
self.upVector = UP_MAPA.default
end
Like I said, this is likely a naïve approach, as I am not 100% sure on how to manipulate CFrames yet.
The problem is that I now get stuck in a rotation-lock.
I’ve googled around for a bit and searched for a bit on here, but have been unable to find anything helpful (or perhaps just glanced over it while skimming titles).
What would be a better approach to this?