I’m working on View Models for gun system and i want to make it easily animatable and also look good without overcomplicated code
What is the issue
Problem is that when i attach arms to gun, no matter which methood, changing CFrame, motor6D, welds, it don’t work or it works but makes animating 100x harder
What i have tried?
I tried few solutions, the one that was the closest was using animations only for everything, but i realized that aiming will look weird, also i tried CFrames and CFrame + Animations
I also read entire dev forum and searched on youtube but every tutorial failed to help
Simple and Robust Joints: When attaching arms to the gun, consider using simple joints like CFrame or Weld instead of complex joints like Motor6D. These joints are easier to animate and maintain.
Pose System: Implement a Pose system to manage the arm positions. This will allow you to easily animate the arms by applying poses to the joints.
Attachment Points: Use attachment points to connect the arms to the gun. This will make it easier to animate the arms and ensure they’re properly aligned.
Here’s an example of how you can use a Pose system to animate the arms:
local arm1 = script.Parent:FindFirstChild("Arm1")
local arm2 = script.Parent:FindFirstChild("Arm2")
local gun = script.Parent:FindFirstChild("Gun")
-- Create a pose for the arm
local armPose = Instance.new("Pose")
armPose.Name = "ArmPose"
armPose.Parent = arm1
-- Create a pose for the gun
local gunPose = Instance.new("Pose")
gunPose.Name = "GunPose"
gunPose.Parent = gun
-- Animate the arm by applying a pose
local function animateArm()
local pose = Instance.new("Pose")
pose.Name = "AnimatePose"
pose.Parent = armPose
-- Apply the pose to the arm
arm1.CFrame = pose.CFrame
end
-- Animate the gun by applying a pose
local function animateGun()
local pose = Instance.new("Pose")
pose.Name = "AnimatePose"
pose.Parent = gunPose
-- Apply the pose to the gun
gun.CFrame = pose.CFrame
end
-- Call the animate functions to test the animation
animateArm()
animateGun()
This example code creates a Pose for the arm and the gun, and then animates them by applying a pose. This approach makes it easy to animate the arms and gun without overcomplicating the code.
How poses works? are they lerped like animations? because now i found out i can use normal animations for stuff like that, but i want to know if there is better solution still
So poses are a fundamental concept in animating characters and objects. They’re not exactly like animations, but rather a way to define the position and rotation of a character or object at a specific point in time. Poses are essentially a snapshot of the character or object’s state at a particular frame. When you create a pose, you’re defining the position and rotation of the character or object’s joints, which are then used to calculate the final pose of the character or object. Poses are not lerped like animations. Instead, they’re used to define a specific state of the character or object at a particular point in time. When you play back a pose, the character or object will snap to that specific state, rather than smoothly interpolating between states like an animation would.
Yes, you can interpolate poses to create a smooth transition between them, while still being compatible with animations. This can be achieved by using the KeyframeSequence class, which allows you to create a sequence of poses that can be interpolated between.
Here’s an example of how you can use the KeyframeSequence class to interpolate poses:
local keyframeSequence = Instance.new("KeyframeSequence")
keyframeSequence.Parent = workspace
-- Create a sequence of poses
local poses = {}
for i = 0, 10 do
local pose = Instance.new("Pose")
pose.Name = "Pose" .. i
pose.CFrame = CFrame.new(math.random(-10, 10), math.random(-10, 10), math.random(-10, 10))
table.insert(poses, pose)
end
-- Add the poses to the keyframe sequence
for i, pose in pairs(poses) do
keyframeSequence:AddPose(pose)
end
-- Play back the keyframe sequence
keyframeSequence:Play()
It would be much better to use animation instances and animation tracks. When you say that you have an issue attaching the arms, there’s probably an issue with your setup.
The hierarchical structure for this example:
Root
This part is invisible. It’s the part that will be set to the HumanoidRootPart CFrame every frame. It’s what everything else is relative to.
LeftArm
This is a MeshPart which you will use to mimic the left arm of a character.
LeftArmJoint:
This is a Motor6D. Parent it like this:
Set the Part0 and Part1 properties like this:
If the left arm is now offset, don’t move it through the move tool. You can see these properties called C0 and C1 in the properties pane for the Motor6D. Modify these until the arm is at the position you want it to be at.
RightArm
Basically same as left arm but on the right.
AnimationController
Just put this as a direct child to the viewmodel. It’s what we’re gonna parent the Animator to.
Animator
As previously stated, just parent this to the AnimationController.
It’s probably useful to parent all your animations you need as Animation instances to the animator for quick and easy loading.
Then, play the tracks as needed.
I dislike people being disingenuous. Posting broken code that doesn’t work and can’t be made to work because it uses non-existant API doesn’t help anyone.
Listen, my friend does not use roblox so he does not know that much. He is just trying to help me help others because I was trying to grow. I understand there are errors and things that don’t exist. I am just trying my best. Now please drop it and leave me be. I don’t want any arguments.
Yk, problem is not in setup, but in CFrame math, when i made ADS - Aim Down Sights
animation editor is simply desynced due to motors being edited by CFrame, on the other hand using motors to attach hands to weapon makes animation very uncomfortable and hard
When you say being edited by CFrame, do you mean modifying C0 and C1 properties?
Do you have the right CFrame maths calculations right now to get the arms to the position you want them to be without animations? If yes, you could set up a short idle track, play it, and immediately set the speed to 0 so it pauses:
Not with animations, but in animator editor, if i use View Model where i move arms via CFrame or C0 animator is very hard to use, also if i’ll use animations all the time view model is active, take in mind that every weapon will have at least 5 different animations, and there will be few weapons out there
Animations are still the best way to go. I still don’t really understand what you mean with your issue in the animation editor, do you think you could provide a video?
Ok i found a word, the problem is that when i want to attach tool both to torso and arms via CFrames like motor6D ones, pivots are literally broken and i can’t fix them or i’ll break ADS, also do you have any tips on how to load animations to reduce memory usage, i heard that loading animations cause memory leaks due to some roblox internal stuff
You can’t animate because trying to animate will break the ADS.
You’re currently doing ADS with CFrame manipulation.
Is that right?
Here’s my ideas:
Change the ADS to an animation.
Globally manage the offset through the ViewModel Root. Make sure it’s the PrimaryPart of the ViewModel.
In terms of loading animations, they’ll definitely be better performant, less code on your end involved, and also much less buggy. If they are memory-heavy, they’ll be your best option. If you need, use multiple ViewModels and animators for each weapon.