Help with procedurally generated spider character's orientation

  1. What do you want to achieve?
    I am currently trying to make a spider-like character with six legs and a feature so that the orientation of it’s body will be somewhat parallel with the ground it is standing on. The best reference example is with this sort of ‘special trick’ for procedurally generated spiders when walking on a slanted surface. featured in this video. (5:50)
    https://www.youtube.com/watch?v=DPpAsjUr278

  2. What is the issue?
    Everything to do with the actual movement of the legs works perfectly fine. The issue is where one part of the script written so that the body of the spider is parallel to the ground, the player’s rotation is messed up while walking. I know it is because of the part that defines the Y axis’s rotation but I’m unsure what to replace the Y axis rotation with.

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I’ve tried making the Y rotation based on the lookvector of the rootpart but it took me a few seconds to realize that if the Y rotation is always based on the look vector, and the character can’t look left or right, then the look vector will always be stuck as well. The character cannot look anywhere because the part of the body I’m trying to rotate is connected with a motor6D to the torso which is connected to the humanoidRootPart. So not even the humanoidRootPart can automatically rotate based on the player’s movement like how it should.

Here is the whole chunk of the script for the body’s rotation

runService.Heartbeat:Connect(function()
	local rayCast = workspace:Raycast(root.Position, -1000 * root.CFrame.UpVector, raycastparams)
	
	if rayCast and hum.MoveDirection.Magnitude >= 1 then
		local rotateToFloorCFrame = mod:getRotationBetween(root.CFrame.UpVector, rayCast.Normal)
		local floorOrientedCFrame = rotateToFloorCFrame * CFrame.new(root.Position)
		
		local dz = (root.Position.Z - target.Position.Z)
		local dx = (root.Position.X - target.Position.X)
		local horizon = math.atan2(dx, dz) ---issue here, but i dont know what to replace it with.
		alignOrien.CFrame = floorOrientedCFrame.Rotation*CFrame.fromOrientation(0,script.Parent.HumanoidRootPart.CFrame.lookVector.Y,0) --used lookvector since horizon dont work right, but not like lookvector works either.
	end
end)
1 Like