How do I manipulate this CFrame value correctly?

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 0s 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

I don’t think {Value *= tiltAmount} does what you want. The part in brackets is an anonymous table, not a closure which is kind of how you’re using it. Im actually not sure what that does. When you have to do a lot of math like this you might be better off updating the CFrame in a RenderStepped loop instead of a tween, this would give you more control. Other than that I’d have to see a video of what it’s doing to know for sure what’s going on with the math.

1 Like

I’m already updated the CFrame in a RenderStepped loop, the TiltAlpha value is what it’s being set to.

I can get a video later, as I’m on a phone right now.

It looks like you just need to keep the tilt from crouching and strafing separate, that way they cant overwrite each other, and multiply them together right before you update the gun.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.