Hey!
I’m currently working on a dynamic footprint system where the character leaves a footprint beneath their foot whenever they walk, however, I’m encountering an issue with rotating said footprint.
Currently, it slants itself on slanted objects (a feature that must stay), and seems to work correctly- however, it doesn’t take after the rotation of the character itself. I’ve been trying to find out how to do this for a while, but I still haven’t been able to. Any ideas how?
Current Behaviour:
https://gyazo.com/172d2f527d156db4f84345ea378e8fbf
Current Script:
--- handles user interace calls made locally and from the server
--@services
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Debris = game:GetService("Debris");
--@libs
local import = require(ReplicatedStorage.import);
local maid = import("modules/maid");
local ignorelists = import("modules/ignoreLists");
--@folders
local debris = import("debris");
--@instances
local footprintModel = import("assets/movement/footPrint")
local particlesOnMaterial = script.Parent.Parent.FootstepsConfig.ParticlesOnMaterial
--@helpers
local function augmentColor3(color, factor)
local r, g, b = color.R, color.G, color.B
r *= factor g *= factor b *= factor
return Color3.new(r, g, b)
end
--@export
return function(leg, character)
-- leg : boolean (if true, then left, if false, then right)
local root = character:WaitForChild("HumanoidRootPart")
-- raycast below the foot
local offset = if leg then -0.5 else 0.5
local raycast = maid:Raycast(root.Position, (root.CFrame.RightVector.Unit * offset) + Vector3.new(0, -3.5, 0), ignorelists.cantHitCharacters)
if not raycast then return end
local hit, hitNormal, hitPosition, hitMaterial = raycast.Instance, raycast.Normal, raycast.Position, raycast.Material
-- clone the footprint
local footprint = footprintModel:Clone()
footprint.Parent = debris
-- set position
local targetCFrame = CFrame.new(hitPosition, hitPosition + hitNormal)
local targetOrientation = root.Orientation
local finalCFrame = targetCFrame * CFrame.fromEulerAnglesXYZ(math.pi/2, 0, 0)
footprint.CFrame = finalCFrame
-- tween transparency & destroy
maid:Tween({Time = 0.75}, {footprint}, {Transparency = 1})
Debris:AddItem(footprint, 2)
-- if it hits terrain, only change color, if not change both color and material
if tostring(hit.Name) == "Terrain" then
footprint.Color = augmentColor3(workspace.Terrain:GetMaterialColor(hitMaterial), 0.85)
else
footprint.Material = hitMaterial
footprint.Color = augmentColor3(hit.BrickColor.Color, 0.85)
en
return footprint
end