Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make this part face the camera properly?

I used the physics springs(hookes law) to give my part an effect, so that that when the players camera turns, the part faces the camera but goes out and back in the camera offset.

local spring = {}
 
function spring.new(position, velocity, target)
	local self = setmetatable({}, {__index = spring})
 
	self.position = position
	self.velocity = velocity
	self.target = target
	self.k = 1
	self.d = 1
 
	return self
end
 
function spring:update()
	local x = self.target - self.position
	local f = x * self.k
	self.velocity = (self.velocity * (1 - self.d)) + f
	self.position = self.position + self.velocity
end

Ok, so the position is the parts location, and the target is the parts target(ignore velocity)

but, when I apply this to the part though, the part doesn't face the camera properly

local Offset = CFrame.new(-.5, -.25, 1.25)

local springee = spring.new(testPart.CFrame.p, Vector3.new(), Offset + Camera.CFrame.p + Camera.CFrame.lookVector)
springee.k = .1
springee.d = .25

game:GetService("RunService").RenderStepped:connect(function()
	testPart.LocalTransparencyModifier = 0
	springee.target = Camera.CFrame.p + Vector3.new(Camera.CFrame.lookVector.X, Camera.CFrame.lookVector.Y, 0)
	springee:update()
	
	testPart.CFrame = CFrame.new(springee.position.X, springee.position.Y, Camera.CFrame.z) * Offset
end)

It's supposed to look at the cameras direction, but instead it just looks at one direction.

If you know how to fix this then please answer, I couldn't find any solution to this.

1 answer

IF you already know how to use the camera which i don't, usually i suggest to find errors and keep on messing with the codes just to see if it works.

1 comment

0

And also be careful of breaking the script

This discussion is preserved as it was. New answers, comments, and votes are closed.