# How do I make a part go in the direction it's facing if the lookVector is in the wrong direction?

So I spend some time making my plane model BUT when I finished, I realized it was facing the wrong direction, meaning this script:
`ship.PrimaryPart.Velocity = ship.PrimaryPart.CFrame.LookVector * speed`
(which makes the ship move in the direction it’s facing) and this script:
`game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame:lerp(ship.PrimaryPart.CFrame * CFrame.new(0,0,-15*scale),.9)`
do not work.
All the second script does is have the camera smoothly follow the plane as it’s moving.

Essentially what I’m asking is how I would change my code to fix this issue. An idea I had was to create an “offset” type vector3 value. For example, my current ship is facing 45 degrees to the left of the original ship, so I could have a value like this: `Vector3.new(0,-45,0)`, but I’m not sure how I would implement that into the code I have here.

Thanks! Let me know if I need to clarify anything.

6 Likes

The lookVector is the direction the part is “facing”. Perhaps you could clarify what the issue is. You don’t have to move the part in the direction it is facing (lookVector) you have upVector, rightVector as well. You can use negative values to get the opposite direction or make your own CFrame or Vector3 value out of whatever criteria you have.

3 Likes

Thanks for responding. After playing around for a few hours, I finally got it to work (it’s probably more complex than it has to be). What I did is take two values: one value (DirectionVector) showing which direction the ship is facing (e.g. (0,0,1) is the default value) and another value (OffsetVector) showing the rotational offset the ship has relative to lookVector.

In this case, the ship was facing 90 degrees relative to lookVector so it’s OffsetVector was (0,90,0). The ship was facing towards positive X, so the direction vector was (1,0,0). Heres the edited code with these values:
`ship.PrimaryPart.Velocity = (ship.PrimaryPart.CFrame * CFrame.Angles(math.rad(ship.OffsetVector.Value.X), math.rad(ship.OffsetVector.Value.Y), math.rad(ship.OffsetVector.Value.Z))).lookVector * speed`

and for the camera code:
`local targetCFrame = ship.PrimaryPart.CFrame * CFrame.new(ship.DirectionVector.Value.X*-15*scale,0,ship.DirectionVector.Value.Z*-15*scale)`
`targetCFrame = targetCFrame * CFrame.Angles(math.rad(ship.OffsetVector.Value.X), math.rad(ship.OffsetVector.Value.Y), math.rad(ship.OffsetVector.Value.Z))`
`game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame:lerp(targetCFrame,.9)`
(in case anyone actually needed this code)

5 Likes

Updated 1/30/21: The previous way of doing this with hinges is no longer possible due to them being removed

The easiest way is to have a dummy part that is facing in the direction you want the model to be

Steps:

1. Install the Studio Tweaks Plugin (Allows you to see the faces of a part, and a lot of other cool stuff)
2. Create a dummy part and align it with the model so that it is centered and it’s facing in the direction you want the model to face
3. Parent the dummy part to the model and set the model’s PrimaryPart to the dummy part

Now whenever you call model:SetPrimaryPartCFrame() it will be relative to the dummy part

10 Likes

Another alternative is to use an attachment within the part then use it’s WorldCFrame or it’s axis. If you don’t want to create a new part and align it to the model.

https://developer.roblox.com/en-us/api-reference/class/Attachment