I am currently working on modifying a placement system from a tutorial. I can not figure out how to change the degree of the rotation (currently set on 90). In the rotation function, I found math.pi/2 which I am aware equals 90 degrees. However, after trying to change this to math.pi/4 to get my desired effect the model did rotate 45 degrees but bounced around (view this link). Below is the function that rotates the model. Any help or suggestions would be much appreciated.
local function render()
if (resting) then
return
end
if (INTERPOLATION) then
local delta = 1/60
springVelocity = (springVelocity + (currentPosition - springPosition)) * INTERPOLATION_DAMP * 60 * delta
springPosition = springPosition + springVelocity
local extentsX, extentsZ = translate(currentExtentsX, currentExtentsZ, cr)
local vx, vz = 9 * springVelocity:Dot(currentXAxis)/abs(extentsX), 9 * springVelocity:Dot(currentZAxis)/abs(extentsZ)
local r
if (not floatEqual(tweenGoalRotation, cr * math.pi/2)) then
tweenStartRotation = tweenCurrentRotation
tweenGoalRotation = cr * math.pi/2
tweenAlpha = 0
end
if (tweenAlpha < 1) then
tweenAlpha = min(1, tweenAlpha + delta/ROTATION_SPEED)
tweenCurrentRotation = angleLerp(tweenStartRotation, tweenGoalRotation, 1 - (1 - tweenAlpha)^2)
r = tweenCurrentRotation
else
r = cr * math.pi/2
end
local effectAngle = CFrame.Angles(math.sqrt(math.abs(vz/100)) * math.sign(vz), 0, math.sqrt(math.abs(vx/100)) * math.sign(vx))
local rotationCFrame = currentAxis * effectAngle * CFrame.Angles(0, r, 0)
local centerCFrame = rotationCFrame + springPosition
for i = 1, #currentObjects do
local object = currentObjects[i]
local x, z = object.px, object.pz
object.model:SetPrimaryPartCFrame(centerCFrame * CFrame.Angles(0, object.r * math.pi/2, 0) + rotationCFrame * Vector3.new(x, object.sy/2, z))
end
if (springVelocity.magnitude < .01 and tweenAlpha >= 1) then
resting = true
end
else
local rotationCFrame = currentAxis * CFrame.Angles(0, cr * math.pi/2, 0)
for i = 1, #currentObjects do
local object = currentObjects[i]
local x, z = object.px, object.pz
object.model:SetPrimaryPartCFrame(rotationCFrame * CFrame.Angles(0, object.r * math.pi/2, 0) + rotationCFrame * Vector3.new(x, object.sy/2, z) + currentPosition)
end
resting = true
end
end