You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I am making a recreation of the Nutcracker from Lethal Company.
- What is the issue? Include screenshots / videos if possible!
To recreate the Nutcracker, I need to have to torso rotate to scan the surrounding area. Basically it rotates 90 degrees every few seconds during the scanning process.
Here is an image with the lower torso colored red for readability:
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
At first I made an animation for it, but I quickly realized this would not suffice due to the other functions the Nutcracker has/does. To try and do this, I attempted to rotate the upper torso, but this just rotates the entire rig.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here is the code if it helps:
task.wait(1)
local pathfindingService = game:GetService("PathfindingService")
local Nutcracker = script.Parent
local rootPart = Nutcracker:WaitForChild("HumanoidRootPart")
local humanoid = Nutcracker:WaitForChild("Humanoid")
local playingAnim = script.PlayingAnim
local nodes = workspace:WaitForChild("Nodes")
local checkedNodes = {}
local currentNode = nil
local queuedNode
local lastNode = nil
local nodeToMove = nil
local pathfindId = 0
local range = 50
local searchPrecision = 15
local function getPath(destination)
local path = pathfindingService:CreatePath()
path:ComputeAsync(rootPart.Position, destination)
return path
end
local function pathFindTo(destination)
pathfindId += 1
local currentPathfind = pathfindId
local path = getPath(destination)
for i,waypoint in pairs(path:GetWaypoints()) do
if currentPathfind ~= pathfindId then
return
end
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
end
local function stopPath()
pathfindId += 1
end
local function playAnim(id)
playingAnim.AnimationId = "rbxassetid://" .. id
humanoid:LoadAnimation(playingAnim):Play()
end
local function stopAnims()
for i,anim in humanoid:GetPlayingAnimationTracks() do
anim:Stop()
end
end
local function getNodeInRange()
local selectedNode = nil
local nodesInRange = {}
for i,node in nodes:GetChildren() do
local distance = (rootPart.Position - node.Position).Magnitude
if distance < range and not table.find(checkedNodes, node) and distance > searchPrecision then
table.insert(nodesInRange, node)
end
end
selectedNode = nodesInRange[math.random(1, #nodesInRange)]
return selectedNode
end
local function movementAi()
local selectedNode = getNodeInRange()
selectedNode.BrickColor = BrickColor.new("Really red")
coroutine.wrap(pathFindTo)(selectedNode.Position)
repeat task.wait() until (rootPart.Position - selectedNode.Position).Magnitude <= searchPrecision
stopPath()
Nutcracker.Torso:PivotTo(CFrame.new())
table.insert(checkedNodes, selectedNode)
selectedNode.BrickColor = BrickColor.new("Lime green")
movementAi()
end
playAnim(132770303101334)
movementAi(currentNode)