Issue with model orientation after setting pivot to arm from camera

Not the best with handling things like pivots etc. I am just using a modified version (soon to be anyway) of the roblox pre-made weapon system. I am instead having the weapon use the players arms them selfs on their model so it replicates what other players view and I also just feel it looks nicer and makes my game stand out.

Anyway.

So the bobbing code seems to be the issue here and I am not exactly too sure what exactly is causing my weapon to point upwards from the point it should be at.

I suck with math or anything that has to do with calculations so do excuse me if this easy for you to figure out. I hope you understand.

Preview:


Code:


-- I have also supplied the constants that are relevant.

	VIEW_MODEL_BIND_NAME = "BlasterViewModel",
	VIEW_MODEL_OFFSET = CFrame.new(0.65, -1, -1.3),
	VIEW_MODEL_BOBBING_SPEED = 0.4,
	VIEW_MODEL_BOBBING_AMOUNT = 0.05,
	VIEW_MODEL_BOBBING_TRANSITION_SPEED = 10,
	VIEW_MODEL_RELOAD_FADE_TIME = 0.15,

function ViewModelController:update(deltaTime: number)
	-- Hide tool instances
	for _, instance in self.toolInstances do
		instance.LocalTransparencyModifier = 1
	end

	-- View model bobbing animation
	local moveSpeed = (self.handle.AssemblyLinearVelocity * Vector3.new(1, 0, 1)).Magnitude
	local bobbingSpeed = moveSpeed * Constants.VIEW_MODEL_BOBBING_SPEED
	local bobbing = math.min(bobbingSpeed, 1)

	self.stride = (self.stride + bobbingSpeed * deltaTime) % (math.pi * 2)
	self.bobbing = lerp(self.bobbing, bobbing, math.min(deltaTime * Constants.VIEW_MODEL_BOBBING_TRANSITION_SPEED, 1))

	local x = math.sin(self.stride)
	local y = math.sin(self.stride * 2)
	local bobbingOffset = Vector3.new(x, y, 0) * Constants.VIEW_MODEL_BOBBING_AMOUNT * self.bobbing
	local bobbingCFrame = CFrame.new(bobbingOffset)
	
	self.model:PivotTo(self.char:WaitForChild("RightLowerArm").CFrame * Constants.VIEW_MODEL_OFFSET * bobbingCFrame)
	--self.model:PivotTo(camera.CFrame * Constants.VIEW_MODEL_OFFSET * bobbingCFrame)
end

1 Like

Okay so I modified the code slightly as I forgot the entire model was the whole view model.

This is now the result. Its better but not straight.

Change: self.model:PivotTo —> self.model.Blaster:PivotTo

you shouldnt call pivot on children of the model, only on model itself, just make sure u have primary part set in the model to one of your model parts

1 Like

The root part is Root, not too sure if that makes things a little more difficult or not. Also from there should I just leave the logic as it is?

The motors are not being used. They cause the player to be flung.

  1. dont use waitforchild every update, send a video cause i dont understand whats wrong

yes its fine just make sure root has same orientation as the actual gun (faces match)

1 Like

You’re right but for some weird reason earlier it had indexed nil so I slapped it there for the moment.

Does the image now show you enough?

It should all match up. Roblox made it after all so I assume everything is setup correctly.

oh wait is it supposed to point at the “camera” ?

No its not. Look at where the hands are pointing. Its off a bit. Ill send two screenshots hold on. I will edit this message. One from the server and one from the cli. It will be very obvious which is which.

@ChiDj123 I hope you can understand the issue at hand now. No the client is not modifying anything on the server just so were clear.

try simply just setting to arm cframe for now see how it is

It already uses the CFrame of the arm could you explain more what you mean?

self.model:PivotTo(self.char:WaitForChild("RightLowerArm").CFrame * Constants.VIEW_MODEL_OFFSET * bobbingCFrame)

If you mean only the arm then it makes no difference. I had tried before.

just do arm for now and view in explorer for ur cframe, faces and orientation of primary part and the arm

1 Like

I think the issue isn’t with the blaster model but the parent model it is contained within. I am pretty sure if I just edit that orientation it should correct its self.

I figured out the issue and have partially fixed it. Since this is the orientation I will close this post. If anyone has a clue about why the gun is floating to the side let me know!

https://devforum.roblox.com/t/what%E2%80%99s-the-hardest-bug-you%E2%80%99ve-ever-had-to-fix/3651301/17?u=thatguybarny1324

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