How to balance a sniper in a runservice

I want to link me something or a code example of how to change the cameraoffset, I’m talking about orientation, position, basically that when I point it moves at random, the pointing script is already done, it is not necessary to give the script because I just want to tell me how I could use math.sin in this case, and that the camera moves like call of duty or something similar, a tutorial or some small hint is useful to me

2 Likes

If you wanted to make a point go around a unit circle by a certain amount in radians, then you’d set the point to be cos(a),sin(a), with a being the angle.

For an example using an arbitrary angle:
At 3.58 radians, the point would be just past halfway.
image

As you probably know, a unit circle’s length in radians is 2pi, and so half of the circle’s length in radians is just pi, so if we set the angle to be pi, it’ll look like this:
image

Now, this works because sine and cosine used together this way position themselves at the end of a triangle’s hypotenuse inside the circle.
image

Blah blah, you get it.

But, we can change the path the point actually takes. So the idea is, plug in some weird irrational numbers for the equation and have the path of the point be a sort of bobbing path on one axis. A good way to make it seemingly not repeat as if it was an actual person holding it is to use two different irrational numbers.

1 Like

a = 0
runservice.RenderStepped:Connect(function()
local a = a + 0.4

end)

hey thanks but one question that is:
image

1 Like

code? how?

1 Like

Youd do something like this after adding to a:
CameraOffset = Vector3.new(cos(a),sin(a),0) then multiply by whatever arbitrary numbers you want.
(Also you might need to swap x and z there if its moving the camera in the wrong way)

1 Like
a = 0
runservice.RenderStepped:Connect(function()
local a = a + 0.4
humanoid.CameraOffset = Vector3.new(math.cos(a),math.sin(a))
end)

Sorry, how do I add the Pi? I know it is necessary but how do I do it?

a = 0
runservice.RenderStepped:Connect(function()
local a = a + 0.4
humanoid.CameraOffset = Vector3.new(math.cos(math.pi(a)),math.sin(math.pi(a)))
end)
1 Like

if you don’t want to help me, no problem, I know I am very annoying.
edit: I don’t mean it in a bad way seriously it sounds weird but I don’t say it normally and I feel ashamed.

1 Like

you can just do math.pi for that!
example:
math.pi*a

Also don’t worry you’re not annoying lol

1 Like

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