So I, when animating numerous things, have come out with numerous problems like “How do I take the magazine off the gun?” and such as that. I heard from a friend that major games like Phantom Forces use tweening to animate players and guns. How does this work and how do I learn? If this is false, how do I animate taking magazines out of guns and pulling bolts back?
Since gun models usually don’t have a humanoid in them, an AnimationController is used instead. This object is like a humanoid in the sense that you can call AnimationController:LoadAnimation() on it. The gun model itself is rigged with Motor6d’s just like an NPC.
I’m pretty sure they wouldn’t be using TweenService constantly for their animation, but I could be wrong. My best guess is that they are using a function of CFrame, called Lerp. This behaves in a similar way to TweenService in that Lerping moves a CFrame towards a CFrame goal by a given increment. This is what a lot of TPS/FPS games do for their characters and guns.
(CFrame:Lerp(cframe goal, increment)) -- returns a cframe moved towards the goal by whatever increment you gave it
I’ve thought about trying out using lerping or tweening for animations but I’ve always come to the problem:
The player moves around, how do I account for this?
And I assume it’s probably very complex math.
OH, and, how do I rig a weapon with Motor6D’s? Like, I’ve been able to make scripts that changes the tool weld from normal weld to Motor6D, but jeez. And how do I even animate that?
For Lerp animations on First person gun models, or on a player’s joints, you would want to make these values additive. Here’s an example of what I mean:
local shooting = CFrame.new(0,0,0)
local gunmodel = workspace.GunModel -- generic gun model we will be animating
local function shoot()
shooting = CFrame.new(1,0,0)
end
game:GetService("RunService").RenderStepped:connect(function()
shooting = shooting:Lerp(CFrame.new(0,0,0), 0.1) -- repeatedly try to set the cframe back to a given value
GunModel:SetPrimaryPartCFrame(workspace.Camera.CFrame * shooting) -- move our gun model in front of the camera, and multiply it by the "shooting value"
end)
So essentially what you would see here is
- shoot function is called, gun model is moved out of place by 1 stud CFrame.new(1,0,0)
- because of our repeating RenderStep function, every frame the gun will try to move itself back to it original place since we are slowly correcting the offset (shooting = shooting:Lerp(CFrame.new(0,0,0), 0.1) .)
There are some very handy plugins for rigging a model, try searching “Motor6D Creator” or something. If you have ever animated something with a Roblox Animation editor (theres a default one that comes as a plugin in studio) then you were moving and posing the Motor6D joints.
Yay, I love complex vector math.
This is really really easy stuff, its barely math. Most of it is just understanding how these functions work, and messing around with some values. There a so many great tutorials on animating, rigging, and otherwise which can be found ,here, scriptinghelpers, or on youtube. That’s how I learned, they were quite helpful.
I know how to animate. I find the issue to be in like, making sure everything matches up. You can’t make two animatios at the same time as far as I’m aware.
Did you read the tutorial? It specifically addresses the problem you describe in OP. It seems like you skimmed through it without paying much attention to content that could be useful to you.
Marfit: IQ 60
That tutorial is INCREDIBLY helpful, thanks man. On the topic of playing it though, I just export it and call :LoadAnimation() on the Humanoid, or do I have to do something specific for the gun and the humanoid?
Since the gun is technically part of the rig there, the exported animation accounts for both the body parts and the gun. If you call LoadAnimation on the Humanoid after replacing the RightHand joint with a Motor6D the single animation for the gun plus rig should play.