So I want to teleport an object, but instead of teleporting it to a specific position or relative to itself, I want to teleport it like 5 studs in front of itself. I’m very new to cframes and teleporting though
2 Likes
All you would do is get the crame of the part and then add onto it using its lookvector
local part = pathtopart
part.CFrame = part.CFrame * part.CFrame.LookVector * STUDS
This will keep its rotation into account also since CFrame is rotation and also position
2 Likes
This is covered in Alvinbloxes tutorial look vector section 36:50, same thing as @dexanddeb mentioned.
Should be through addition since the direction vector we are moving the part CFrame is relative to world space.
part.CFrame = part.CFrame + part.CFrame.LookVector * STUDS
2 Likes
uhh hmm, I implemented your code, but it’s not moving at all. I put the local part correctly and the studs to 5, but it isnt moving
1 Like
LookVectors are Vector3s, and you can’t multiply Vector3s by CFrames. Changing a part’s position doesn’t modify it’s orientation though, so it’s safe to do this:
part.Position += part.CFrame.LookVector * STUDS
3 Likes
Oh wow! its works perfectly thanks!