Implementing animatable objects inside an animation and be able to script it

I’ve been doing scripting and animating lately and i have a hard time to figure out how people implementing animatable objects / multiple objects inside an animation and implementing it in game and also through scripting. For instance , making multiple objects appear in an animation and be able to rotate and move it and having it dissapear after the animation stops . Forgive me if i’m asking a dumb question

heres an video example ;

1 - you can see that the ramrod / metal rod is moving and rotating
2 - Multiple objects appear like the measured powder and the ramrod in an animation and dissapear

I am aware and i’ve tried moon animator also blender to make animations . So far moon animator lets you parent an object and animate them . but i’m not sure how do you programme it into a game with the objects animated without just the rig animate

Its been years since i last used Roblox Studio so i’m sorry since i don’t remember if i have tried implementing this inside RS with what scripting methods that i tried and sorry for my bad english . Also this is my first post :>

2 Likes

Hi! :wave:
As the animator, I can say that the animation you have shown has multiple animated joints called “Motor6D”, attached to parts, like metal rod and measured powder you’ve mentioned. They’re also making your character stand, walk, jump and fall with animation because parts that character has it has multiple Motor6D’s!

For demo, I have viewmodel arms, which are animated using Motor6D:

As the programmer, you can make such animated joints and connect them to part using code. But you should have a part to animate it, of course!

For coding, we have this best animation to code, it’s a little simple to do, if you have Moon Animator, because it’s comfortable to work with it:

Lets make it code in some steps:

  1. Get to Motor6D of your part to animate:
  2. Click on Motor6D and remember the C0’s CFrame, Part0 and Part1 - you will need them for coding (in my case, Part0 was Right Arm and Part1 was a Bloxy Cola):
    Screenshot_15
  3. Now getting to coding! I have duplicated my Bloxy Cola to ReplicatedStorage, but you can get your part to animate in other way. We’re creating variables for navigation and creating new Motor6D to attach them to parts by using Instance.new:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local PartToClone = game.ReplicatedStorage.Part -- This is my Bloxy Cola

local PartToAttach0 = PartToClone:Clone()
local PartToAttach1 = Character:WaitForChild("Right Arm")

PartToAttach0.Parent = PartToAttach1

function rad(x: number)
	return math.rad(x)
end

local Weld = Instance.new("Motor6D")
Weld.C0 = CFrame.new(Vector3.new(-0.071, -1.077, -0.107)) * CFrame.Angles(rad(89.944), rad(0), rad(0))
Weld.C1 = CFrame.new(Vector3.new(-0.011, -1.187, -0.105))

Weld.Part0 = PartToAttach0
Weld.Part1 = PartToAttach1

Let me know if you’ve got issues or you need more information!

1 Like

Additionaly, you can play your animation with animated joint, I forgot to add it in the code but I hope you know how to do that.

1 Like

Whats the use of function rad that you’ve mentioned .

1 Like

In CFrame.Angles, we put degrees, so the rotation will be applied with the position. When I first time tried to rotate part within Motor6D using degrees - it was a little off.
So, we have radians in that case. The function has parameter x, which is degrees, then the mathematical formula (math.rad) converts x to radians and then our function returns result of convert!

edit: The reason why I did that in function because it will be shorten and light to use.

where did you get the other C1.Cframe “Weld.C1 = CFrame.new(Vector3.new(-0.011, -1.187, -0.105))” since C1.Cframe set to 0,0,0

I did what you told me but the rotation of the bloxy was off

and not like this

1 Like

Moon Animator has an Easy Weld that allows the object your welding to be animatable without having to do all this CFrame math yourself,

image

1 Like

I sorta did it in a diff way . This time using a different model in this case is a sword model . Then weld BodyAttach(Part) to the sword as a handle using Easy Weld and set animatable to false for the rig to hold it. Idk if this is the right way to do this but at least i got it to work

2 Likes

Oohh gosh, I’m so sorry!!
I were welding both parts with Easy Weld that cames from Moon Animator 2.
It should only change the C0 CFrame, not the C1.

You have to set up only C0 in the code like I did, C1 is better left to zero.

I’m so sorry for my mess.