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

Unable to cast Vector3 to CoordinateFrame?

Asked by 7 years ago

Hi! I'm currently doing something with the Roblox PathFindingService. I'm trying to CFrame a model so that it points to the point and then moves the model to that point. However, I'm running into an issue. When I try to set the CFrame of the primary part of the model I want to move I get an error.

Unable to cast Vector3 to CoordinateFrame

This is happening when I'm rotating the model to match the point I'm getting from the PathFindingService. The point is a Vector3 so I'm not sure why it's not working. Here is my script.

local Plane = game.Workspace.Plane
local PathFinding = game:GetService("PathfindingService")
local Start = Plane.PrimaryPart.Position
local End = Vector3.new(0, 0, 0)
local Path = PathFinding:ComputeSmoothPathAsync(Start, End, 500)
local Points = Path:GetPointCoordinates()

for _,v in pairs(Points) do
    local Part = Instance.new("Part")
    Part.FormFactor = Enum.FormFactor.Custom
    Part.Size = Vector3.new(1, 1, 1)
    Part.Position = v
    Part.Anchored = true
    Part.CanCollide = false
    Part.Parent = game.Workspace
end

for _,v in ipairs(Points) do
    repeat
        Plane:SetPrimaryPartCFrame(Plane.PrimaryPart.Position, v)
        Plane:SetPrimaryPartCFrame(Plane:GetPrimaryPartCFrame() + Plane:GetPrimaryPartCFrame().lookVector * 0.5)
        wait()
    until (v - Plane.PrimaryPart.Position).magnitude < 3
end

The issue is happening on line 20. Where it says Plane:SetPrimaryPartCFrame(Plane.PrimaryPart.Position, v). I'd also like to know too how I would go about rotating the model in steps so that it animates the rotating instead of just rotating to the point instantly. Thanks!

0
You can use a BodyAngularVelocity to rotate what you want. hiimgoodpack 2009 — 7y

1 answer

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

That line errors because you didn't actually construct the CFrame. I assume you meant this:

Plane:SetPrimaryPartCFrame(CFrame.new(Plane.PrimaryPart.Position, v))

As for rotating in steps, it would probably be most natural if you implement some kind of Bezier Curve function, to take into account 'cutting corners' when flying, as planes can't actually make pinpoint turns.

Additionally, I would suggest instead of always moving 0.5 studs every wait(), I'd catch the return value of wait() (the exact amount of time passed) and multiply it by a speed value to get a stable movement speed regardless of framerate.

0
Thanks a lot! thebootsie123 160 — 7y
Ad

Answer this question