I’m pulling my hair out trying to solve this problem and after multiple days of searching for a method, formula, or example and experimenting on my own without any luck, I decided to give the forum a shot (this is my first post!) to see if anyone out there could give me some suggestions on how to accomplish what I’m after. I apologize for the poor quality of the included graphs, I didn’t really know of a better way to visually show this issue.
Assumptions:
All Blocks have the same look vector. (Facing the same direction)
Red = Player (Can move in any direction)
Pink = Pet (Lets assume that this block does not move)
Blue = The target position / location I’m trying to calculate for at any orientation. Essentially, the blue block is a combination of the X and Y from the Red and Pink. Ultimately, I’m trying to calculate the distance from the red square to the blue square (The horizontal distance between the two points but with both of them having the same vertical position).
I feel like I’m missing something very obvious, but I can’t seen to figure out how to do this given that the player can move at any angle and in any direction as indicated by the second included chart. Thanks for the help, advice - hopefully someone can provide a method or direction to focus my efforts.
local blue = workspace.Blue;
local red = workspace.Red;
local pink = workspace.Pink;
while true do
wait(0.1);
local cf = pink.CFrame:ToObjectSpace(red.CFrame);
local xdist = cf.X;
blue.CFrame = red.CFrame*CFrame.new(-xdist,0,0);
print(xdist)
local ang = red.CFrame-red.CFrame.p;
pink.CFrame = CFrame.new(pink.CFrame.p)*ang
end
This is actually very, very close. I’m struggling to understand exactly what is going on and adapt it accordingly and I think my original request / explanation was lacking in some details. I’ve included some more screenshots that I’ll try and explain: Basically, this would be an additional parameter in flocking simulation. What I’m trying to accomplish is to apply flocking to a set of objects AND have those objects follow the players position. The issue is that when following the players position directly, they zig-zag in and out of formation attempting to reach the players position (I’m using the Humanoid Root part for this location (Red Dot). To avoid the zig-zag behavior, i’m attempting to create positions offset (Blue Dots) from the players position based on the horizontal distance from the player to the object following. This would allow the boids to apply the flocking rule set and follow the player without the zig-zag motion.