Hello,
I am working on a tilt for an FPS game. There is a CFrameValue in ReplicatedStorage called TiltAlpha (important later). When your character moves sideways, the gun will tilt slightly in that direction.
I was trying to get this to work with crouch, to make your gun tilt to the left when you do. It works well and is fine until you move sideways.
You see, when you move sideways, the TiltAlpha value mentioned before will be tweened to the new CFrame, and the weapon’s CFrame will be updated accordingly:
weaponModule:Tilt(CFrame.Angles(0, 0, math.rad(-10)), TweenInfo.new(0.3))
tweenService:Create(tiltAlpha, tweenInfo, {Value = tiltAmount}):Play()
humanoidRootPart.CFrame *= tiltAlpha.Value
This is where the problem starts. If I tween the value like this:
CFrame.new(0, 0, 0)
…the weapon will return to its original position. This means whenever I use any 0
s in a tilt CFrame, it will change that weapon’s coordinate to its original position.
Thus, when you crouch and the gun tilts, and you move sideways, the gun will return to its original position, which isn’t what I want.
I’ve tried tweening like this to fix the problem:
tweenService:Create(tiltAlpha, tweenInfo, {Value *= tiltAmount}):Play()
…but that errored. I can’t use a variable like this:
local newCFrame = tiltAlpha.Value *= tiltAmount
…because that will interfere with other tweens that are already playing.
Whoo, that was a lot to type. Hope you could understand what I was saying. Anyway, does anybody have any ideas to work around this problem? I would greatly appreciate it.
Thanks,
Fizzitix