Hello, I’m wondering how to create an effect where when you land the camera bobs up and down slightly once. I know there’s two posts on it, but I’m still confused.
Secondly, does anyone know how to create a momentum system where, for example, you jump forward but while in the air, you’re unable to move anywhere else? Basically just how you jump irl.
This script(goes into StarterCharacterScripts) uses Humanoid.StateChanged to see when the player jumps and lands. You can adjust the settings of the tweens if you feel like, but I found the Back easing style worked best for the landing effect:
local TweenService = game:GetService("TweenService")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local FallTween = TweenService:Create(Humanoid,
TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In),
{CameraOffset = Vector3.new(0, 5, 0)})
local LandTween = TweenService:Create(Humanoid,
TweenInfo.new(0.35, Enum.EasingStyle.Back, Enum.EasingDirection.Out),
{CameraOffset = Vector3.new(0, 0, 0)})
Humanoid.StateChanged:Connect(function(Old, State)
if State == Enum.HumanoidStateType.Freefall then
FallTween:Play()
elseif Old == Enum.HumanoidStateType.Freefall then
LandTween:Play()
end
end)
I tried using the new CharacterController and they would supposedly allow you to tweak settings about your character, including being able to adjust the force your character could push itself with mid-air. Unfortunately, I didn’t get it to work, so I modified the last script I sent to this:
local Force = 1500
local TweenService = game:GetService("TweenService")
local Humanoid : Humanoid = script.Parent:WaitForChild("Humanoid")
local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local FallTween = TweenService:Create(Humanoid,
TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In),
{CameraOffset = Vector3.new(0, 5, 0)})
local LandTween = TweenService:Create(Humanoid,
TweenInfo.new(0.35, Enum.EasingStyle.Back, Enum.EasingDirection.Out),
{CameraOffset = Vector3.new(0, 0, 0)})
local Velocity = Instance.new("LinearVelocity")
Velocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
Velocity.PrimaryTangentAxis = Vector3.xAxis
Velocity.SecondaryTangentAxis = Vector3.zAxis
Velocity.Attachment0 = HumanoidRootPart.RootAttachment
Velocity.MaxForce = Force
Velocity.Enabled = false
Velocity.Parent = HumanoidRootPart
Humanoid.StateChanged:Connect(function(Old, State)
if State == Enum.HumanoidStateType.Jumping then
Velocity.Enabled = true
local V = HumanoidRootPart.AssemblyLinearVelocity
Velocity.PlaneVelocity = Vector2.new(V.X, V.Z)
end
if State == Enum.HumanoidStateType.Freefall then
FallTween:Play()
elseif Old == Enum.HumanoidStateType.Freefall then
Velocity.Enabled = false
LandTween:Play()
end
end)
It does the same as before with the camera movement, but now every time you jump a VectorVelocity locks your X and Z movement to what it was when you left the ground. Adjusting the Force variable will determine how much the player can strafe mid-air. A lower value means the VectorVelocity doesn’t push as much, allowing the player to accelerate faster and a higher value means the player cannot strafe as rapidly. I found 1500 to be a fitting value, but feel free to change it.
just to help out, in order to achieve a " a momentum system where, for example, you jump forward but while in the air, you’re unable to move anywhere else"
using the CharacterController that @XSiggeManx mentioned,
you set AirController.MoveMaxForce to 0.
This will prevent any additional forces while in the air. Player input does nothing. But you will still maintain momentum if you jumped from a running start, or a moving platform. If you get bumped by something while in the air you’ll get a realistic result.
What @XSiggeManx 's solution does, is apply a force to the character that forces it to maintain its (X/Z) velocity thru the entirety of the jump. If you get bumped by something while in the air, your character will still be applying a force to itself that attempts to maintain its original velocity.
Either solution is totally fine depending on what you’re looking for! Just wanted to give extra clarity.