Char:TranslateBy(Car.Value.Cam.Position)
The char should be teleported to the Block but the char is teleporting somewhere other. Why?
Char:TranslateBy(Car.Value.Cam.Position)
The char should be teleported to the Block but the char is teleporting somewhere other. Why?
Ah, the thing to keep in mind here is that TranslateBy(Vector3) is not exactly a teleport. Rather, it shifts the model Vector3 away from where it is currently. if you want to move or teleport the model to a specific location, then there are two ways of doing it.
The first way: you can instead use the method :MoveTo(Vector3) to move the model to the nearest place above wherever Vector3 is located in 3D space. Note that if you need the teleport to be exact (teleporting a car into a small tunnel, etc.) you will need the second way.
The second way: you need to do two things. 1, the model you are teleporting must have its PrimaryPart property set. You can set this by clicking on the property field, and then clicking on the desired part within the Explorer tab. 2, you can now use the method :SetPrimaryPartCFrame(CFrame) to teleport the model to the exact location in 3D space, including even the exact orientation if you wish. Note however that you may need to manually shift the height of the CFrame within the script in order keep the model from getting stuck in a wall or the ground.
Here are 4 examples based on your code above:
-- The first way (teleports Char to above the Cam's Position)
Char:MoveTo(Car.Value.Cam.Position)
-- The second way (without rotation)
Char:SetPrimaryPartCFrame(CFrame.New(Car.Value.Cam.Position))
-- The second way (this time with rotation)
Char:SetPrimaryPartCFrame(Car.Value.Cam.CFrame)
-- What about teleporting the car to in front of Char? (Assuming PrimaryPart property has been set)
Car.Value:SetPrimaryPartCFrame(
Char.Torso.CFrame
+ Char.Torso.CFrame.lookVector*20 -- Makes sure it ends up in front of Char, not inside!
+ Vector3.new(0, Car.Value:GetExtentsSize().Y / 2, 0) -- Gotta make sure it doesn't end up in the ground
)
This discussion is preserved as it was. New answers, comments, and votes are closed.