Hello everyone and this is my third fps tutorial and is the second part! I did it as I stated in my last tutorial that I will make a tutorial on advanced systems.
Disclaimer: I am new to FPS making so please point out any errors or mistakes and I will be using the basics of this video here .
In this part we will be covering on how to make the gun aim and add idle animations.
Lets begin!
1. Aiming
Now we will be making the gun aim, I will do it a bit simpler way of trying to guess the offset instead of making an aim part.
-
In the framework we will add a new CFrame variable called aimcf:
-
Now make a bool and call it aiming:
-
And last but not least inside the run function:
if aiming then
--we will put something inside this shortly
else
--also soon
end
--note put this under the set primary part cframe
Now finally we put in the script:
- If aiming true:
aimcf = aimcf:lerp(weaponmodule.aimcf, 0.1) --the cframe offset and the speed
- If aiming false:
aimcf = aimcf:lerp(CFrame.new(), 0.1) --resetting the cframe
Now inside the gun module add a setting called the something like aimcframe or something.
Settings.aimcf = CFrame.new(0,0,0) * CFrame.Angles(0,0,0) --the aim offset dont do anything yet
2. Key binding
In this part we will make the gun actually aim.
lets begin!!!11111
- For aiming we dont need User Inpur Service since right mouse button can be accessed with mouse.
Check if you have mouse variable if not:
local mouse = plr:GetMouse()
Now finally lets detect when right mouse button is pressed down:
mouse.Button2Down:Connect(function()
-- our script will be here
end)
And when its released:
mouse.Button2Up:Connect(function()
-- we will add our script here soon
end)
Now are you ready for the script?
Inside button down:
aiming = true
Inside button up:
aiming = false
3. Animations
In this part we will only do idle animation. I will try and explain this part as best as I can.
- Inside the module create a setting called idleanim
Settings.idleanim = "rbxassetid://"
Now inside setup we will set it as the animation like this:
local idle = Instance.new("Animation", currentweapon)
idle.AnimationId = weaponmodule.idleanim
local idleanim = currentweapon:WaitForChild("Humanoid"):LoadAnimation(idle)
idleanim:Play()
Now make your animation, publish it and get the animation id.
I will leave all the animations in animsaves inside the viewmodel.
- Insert the animation into the setting inside the module.
Test if it works!
4. The aiming offset
This will we a short part of the tutorial I will just explain a bit on how to guess it faster.
- Tip 1
CFrame.new(left-right, up-down, forward-backwards) - Tip 2
Dont be scared to use values like:
CFrame.new(0.112,0.505,-1.2) the more numbers you add after the dot the less bigger it will be - Tip 3
Try eyeing it, look how one stud looks and dont be afraid to experiment.
5. Outro
Thank you for reading this I really appreciate it thank you for everyone who commented who reported errors and really big thanks to GamerRyan18 who taught me a lot about FPS.
Next time we will maybe doing gun sway? Maybe shooting? You will need to wait to find out!
Part 3: Working on it…
Part 1: FPS Tutorial [Part 1]
Thank you and see ya later!
P.S the place also got updated.