Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a part attracted to another part?

Asked by 6 years ago

Think of a game like F-Zero. The race cars can move around and gravity always goes towards the race track. Essentially, I want to make a part (Part A) attracted to the nearest point on another part (Part B). My idea was to use raycasting to cast a ray straight down from Part A, and have a BodyPosition in Part A that would pull Part A to where the ray intersects with Part B. However, I ran into the problem that I could not make a ray oriented relative to Part A's orientation. This is my code, inside of a BodyPosition, inside of Part A:

while true do
    wait()
    part, point = game.Workspace:FindPartOnRay(Ray.new(script.Parent.Parent.Position,script.Parent.Parent.Orientation))
    script.Parent.Position = point
    print(part)
end

I am not married to the raycasting idea, so if you have another suggestion that would also be appreciated. Thanks.

(The complete line that might get cut off is: part, point = game.Workspace:FindPartOnRay(Ray.new(script.Parent.Parent.Position,script.Parent.Parent.Orientation)) )

Answer this question