Hey guys. I want the character to play a different idle animation after unsheathing the sword and after sheathing the sword back, it plays a normal idle animation again. Changing the id of the idle animation of roblox animate script isn’t the best idea, because it doesn’t play the animation immediately, only if you move, so I want to find a different way. If you have any ideas or script examples, I’d really appreciate it if you share them with me. Thanks in advance.
I think the best way here is to make the stance’s animation priority higher than the idle animation, then play it when the sword is equipped and stop it when it’s unequipped.
P.S. Sorry if I’m late
Just playing the animation won’t work, because if you start to move, this idle animation will still play and it looks weird.
Then you can use RenderStepped to check on the HumanoidRootPart’s velocity magnitude.
local RunService = game:GetService("RunService");
local HRP = game.Players.LocalPlayer.Character.HumanoidRootPart;
RunService.RenderStepped:Connect(function()
if HRP.Velocity.Magnitude < 1 then
-- play animation (only if it isn't already playing)
else
-- stop animation
end;
end);
Yeah, that’s a good idea. I’ve done something similar to this some time ago, I want to know, what is better to use and will cause more lag, your idea or this:
function Stance()
if Opened == true then
if Humanoid.MoveDirection == Vector3.new(0,0,0) then
if not StanceAnim.IsPlaying then
StanceAnim:Play()
end
else
StanceAnim:Stop()
end
end
end
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(Stance)
Sure that can work too, however, you would still have to use magnitude or find another method to compare the MoveDirection as you cannot compare two Vector3s like you’re doing here:
MoveDirection == Vector3.new(0, 0, 0) -- this will error as you cannot compare two Vector3s (or Vector2s)
I don’t understand what are you talking about, the script works without any errors. I’d just like to know what of these two methods will cause less lag.
I have a similar issue to yours, and I learned a pretty consistent and easy way to deal with it!
Basically I have my weapon have an Animation Instance that plays the idle whenever the character is holding the weapon.
Whenever they draw the sword, I tell the animation to play. Whenever they remove it, I tell them to stop. One rule I have with this idle animation is that I do not touch the legs. The only things that are edited in this animation is the lower torso and everything above. This way, the Animate script will play the walk/run animations while the player holds the sword.
This method allows you to replicate the animation without having to change it in Animate, and it looks the most natural to me. There are no conflicting errors because of the priority that the animation has.
Thank you for the response. Your idea is pretty good, but I don’t want to hold the sword in front of me if I walk, moreover I’d like to add a walking animation as well, but the topic is not about it, so I want to use some function, that will detect if a player walks or stands still to animate it, according to it’s actions.