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

is it possible to use Moveto with CFrame instead of Vector3?

Asked by
nachsor 36
5 years ago

Hello, my name is nachsor(aka skelyvelocirap). I am in the progress of making a game on Roblox, it is fairly close to being playable but I did encounter a problem :|. I am trying to move a model to the position my mouse is at but I need to use CFrame. There is this MoveTo() Function which I have an issue with. When I try feeding it a Frame value:

mtarget:MoveTo(CFrame.new(posX, 0, posZ))

it just shows me an error: 14:17:23.212 - Unable to cast CoordinateFrame to Vector3

This error is fairly annoying as I really want to use CFrame for it as my game is a sandbox Tycoon (not the name) and I want the placement system to place the models at a specific hight but go through blocks if needed.

Is there a way to use Frame instead of the Vector3?

thank you -nachsor

0
There's a function called SetPrimaryPartCFrame that uses a CFrame Rare_tendo 3000 — 5y
0
I did use it but you can only add, subtract or multiply the value, not set the value to a specific amount. nachsor 36 — 5y
0
wdym Rare_tendo 3000 — 5y
0
oh never mind, I probably used it in conjunction with something that made it do something weird. Thank you very much, it works very good with this: mtarget:SetPrimaryPartCFrame(CFrame.new(posX, 0, posZ)) nachsor 36 — 5y

1 answer

Log in to vote
2
Answered by
jaschutte 324 Moderation Voter
5 years ago

Why don't you use SetPrimaryPartCFrame? Just make sure that the model has a hitbox and that the models primary part is the hitbox.

I am pritty sure that this: 'add, subtract or multiply the value, not set the value to a specific amount.' is false. As the function it self is named: SETprimarypartcframe.

Anyways, to awnser your question. No it is not possible, you need to use SetPrimaryPartCFrame or loop over every part in the model. Here is how you can do it with SetPrimaryPartCFrame:

--For this to work there needs to be a part in the model named hitbox and that is set as primary part.
mtarget:SetPrimaryPartCFrame(CFrame.new(posX, 0, posZ))

The problem with MoveTo() is that it positions the model, what that means is that if there is another part in the way, it will move above that part instaid of ignoring that part. With models that have bricks outside of thier hitbox this can be an issue. -And you aren't able to rotate the model, which also can be a problem. If you need to use MoveTo() you can use this:

mtarget:MoveTo(Vector3.new(posX, 0, posZ))
--or use \/ but /\ is more efficient.
mtarget:MoveTo(CFrame.new(posX, 0, posZ).p)
0
ok thank you nachsor 36 — 5y
Ad

Answer this question