So many people have told me to do something similar to:
Humanoid:MoveTo(Pos+Vector3.new(5,0,0))
Or
Humanoid:MoveTo(Pos+Vector3.new(0,0,5))
But the problem with this is that it will always be on the x or z axis. I just want the Humanoid to move to a position 5 studs away no matter the axis (preferably the closest possible).
So how would I do this? If you do need more information do comment.
basically, the pythagorean identity establishes that:
sin^2(?) + cos^2(?) = 1 (? being the angle measure / radians)
Which, if you, on a graphic calculator like desmos, were to graph
r = sin^2(?) + cos^2(?) (r standing for radius)
you would end up with a circle with radius 1
With that said, you could manipulate it so that you end up with a circle of any radius, for example, if you wanted a circle with radius a
or radius 5
, you could do:
r = asin^2(?) + acos^2(?)
r = 5sin^2(?) + 5cos^2(?)
local sPos = Vector3.new(1,0,2)--starting position local function stud (theta) local pos = Vector3.new(5*math.sin(theta),0, 5*math.cos(theta)) local finPos = sPos + pos print((finPos - sPos).magnitude,"::",pos,"::",finPos,"::",math.deg(theta)) end for i = 1, 360 do stud(math.rad(i)) end
Or more simplfied:
local humanoid = --humanoid object of your choice local theta = math.rad(69)--for the memes local sPos = Vector3.new(1,0,2)--some starting position local pos = Vector3.new(5*math.sin(theta),0,5*math.cos(theta)) local finPos = sPos + pos --finished position print((finPos - sPos).magnitude)--check distance humanoid:MoveTo(finPos)
Note that I did not do 5*math.sin(theta)^2
or 5*math.cos(theta)
in that script
This is probably the part of the answer I'm going to be lambasted for due to incorrect terminology,so i recommend skipping this part, if you already know the math behind it. But nevertheless, I digress. Put simply, this works, because, essentially, and point on a circle is reachable with a right triangle.
For a certain angle measure ?, the hypotenuse is the radius of the circle(r), as it reaches from the center to the edge of the circle. the vertical side would be r* sin(?) and the horizontal side would be r*cos(?).
This, on a circle with radius 1 would mean that the hypotenuse is 1, the vertical side is sin(?) and the horizontal side is cos(?), using pythagorean theorem gives us the famous equation of
sin^2(?) + cos^2(?) = 1
Here is the part of the answer where you see people explain the concept far better than i did
Hopefully this helped!
You would possibly be best using something like an Artificial Intelligence Script and then adjusting it so you can target what it moves. If you want to do it another way, I believe it would be quite hard due to having to calculate several positions.
Hope this helps.