Hello, I can’t seem to figure out how to align my “Footprint” part with the ground and make it point to the next waypoint.
A is supposed to point towards B while staying aligned with the ground
Here’s what I got so far:
function animalModule.createFootprints(animal, waypoints)
local footstepFrequency = 5
local count = 1
for i, wp in pairs(waypoints) do
count = count +1
if count == footstepFrequency+1 then count = 1 else continue end
local rayOrigin = wp.Position
local rayParams = RaycastParams.new()
if animal.char then
rayParams.FilterDescendantsInstances = {animal.char}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
end
local rayDirection = Vector3.new(0,-5,0)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, rayParams)
if raycastResult and i+1 < #waypoints then
local mat = raycastResult.Material
if mat == Enum.Material.Grass or mat == Enum.Material.LeafyGrass or mat == Enum.Material.Mud then
local footstep = Instance.new("Part", workspace.Footprints)
footstep.Size = Vector3.new(4,4,.1)
footstep.Transparency = 1
footstep.CanCollide = false
footstep.Anchored = true
footstep.Name = "Footprint"
footstep.CFrame = CFrame.lookAt(raycastResult.Position, raycastResult.Position + raycastResult.Normal)
local decal = Instance.new("Decal", footstep)
decal.Face = Enum.NormalId.Front
decal.Texture = "rbxassetid://"..animal.footprintIds[math.random(1,#animal.footprintIds)]
game:GetService("Debris"):AddItem(footstep, animalModule.footprintLifetime)
end
end
end
end
I’m only creating a Footprint for every 5 waypoints, but I want each Footprint to point towards the next waypoint.
Any help would be appreciated!