What do you want to achieve?
I want to adjust my animations accordingly to the players movement speed.
What is the issue?
The simple check of the RootPart’s Velocity Magnitude provides wrong results when on rotating platforms. While the issue is miniscule, I still love to add those little details to my games.
What solutions have you tried so far?
At first I thought it was simple, just subtract the velocity of the platform, but it only works if the platform isn’t rotating!
function update_speed() : nil
local base_speed = animation_variables.BaseSpeeds[current_anim]
if base_speed then
local character_vel = root_part.AssemblyLinearVelocity
local ground_vel = Vector3.zero
if controller.ActiveController:IsA("ClimbController") then
ground_vel = climb_sensor.SensedPart.AssemblyLinearVelocity
elseif controller.ActiveController:IsA("GroundController") then
ground_vel = ground_sensor.SensedPart.AssemblyLinearVelocity
end
set_animation_speed((character_vel - ground_vel).Magnitude/base_speed*movement_direction)
end
end
A few extra notes I’d like to mention is that I do use the new Physics - Based Character Controller.
Found the solution! I can’t explain it at all but it works, lol.
local function update_speed()
local base_speed = animation_variables.BaseSpeeds[current_anim]
if base_speed then
local character_vel = root_part.AssemblyLinearVelocity
local ground_vel = Vector3.zero
if controller.ActiveController:IsA("ClimbController") then
if climb_sensor.SensedPart then
ground_vel = climb_sensor.SensedPart.AssemblyLinearVelocity
local angular_vel = climb_sensor.SensedPart.AssemblyAngularVelocity
local relative_pos = root_part.Position - climb_sensor.SensedPart.Position
local rotational_vel = angular_vel:Cross(relative_pos)
ground_vel = ground_vel + rotational_vel
end
elseif controller.ActiveController:IsA("GroundController") then
if ground_sensor.SensedPart then
ground_vel = ground_sensor.SensedPart.AssemblyLinearVelocity
local angular_vel = ground_sensor.SensedPart.AssemblyAngularVelocity
local relative_pos = root_part.Position - ground_sensor.SensedPart.Position
local rotational_vel = angular_vel:Cross(relative_pos)
ground_vel = ground_vel + rotational_vel
end
end
set_animation_speed((character_vel - ground_vel).Magnitude / base_speed * movement_direction)
end
end