Changing orientation changes position

I’m just trying to update the orientation of this part, originally I was using CFrames but I thought maybe my CFrame maths was wrong. I decided to only change the orientation of the part but somehow the position is being changed?

print(speed)
shape.Position += speed * dt
speed += Vector3.new(0,-10,0) * dt -- Gravity wowzers
print(shape.Position)
shape.Orientation = CFrame.new(shape.Position,shape.Position + speed * dt).LookVector
print(shape.Position)

The code above somehow results in the shape’s position being set to (0,- large number, 0)

image

Line 35 is print(speed), Line 38 is the first print(pos) and line 40 is the final print(pos)

This system works as long as I never touch the orientation and I’m not sure why changing the orientation suddenly changes the position. Any help would be greatly appreciated

I have figured out the error, when dt is 0, it sets the value to of vectors to nan, bellow is code to fix it.

local ori = CFrame.new(shape.Position,shape.Position + speed * dt).LookVector
if ori ~= ori then
	ori = Vector3.new(0,0,0)
end
shape.Orientation = ori*180/math.pi

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