How can i keep orientation on cframe when moving cframe

image

original oritentation

Piece.CFrame = CFrame.new(DesiredPart.CFrame.X, Piece.CFrame.Y, DesiredPart.CFrame.Z)

image
How can i get the orientation to not reset?

just rotate it yourself by multiplying by CFrame.Angles(0,math.rad(90),0)

1 Like

This should work.

local object = "your object"
local AmountToMoveOnXAxis = whateveryouwant
local AmountToMoveOnYAxis = whateveryouwant
local AmountToMoveOnZAxis = whateveryouwant

object.CFrame = Object.CFrame * CFrame.new(Vector3.new(AmountToMoveOnXAxis, AmountToMoveOnYAxis, AmountToMoveOnZAxis))

Its a different system of movement however. :slight_smile:

You copy over the rotation CFrame before moving it, then say newPosition * oldAngle to have a new position but same angle.

local oldRot = this.CFrame.Rotation -- copies over only the rotation stuff but new CFrame
-- .Rotation is read only, so we cant manipulate it like we can with others
-- for this case we are only copying over the data for later use

-- when moving the chess piece
this.CFrame = CFrame.new(newPosition) * oldRot
-- CFrame.new(Position) creates a new CFrame using a Vector3 Position
-- Multiplied by Rotation will tell it which direction to face
-- This effective keeps the rotation while having a new position

Keep in mind that the Rotation is handled in Radians, so the number will appear as a decimal, if you want o know the real value, use math.deg() to convert to degrees.

That wouldn’t work because if the original orientation of the piece was 0,0,0, then it wouldn’t do anything.

You need to set the rotation individually.

1 Like

Thats normal behavior, in fact its almost like 0 + 0 = 0.

On a serious note, you can set both Position and Rotation at the same time as a CFrame value is a combination of both of them, all you need to say is Position * Rotation, the other way around will make the Position relative to the Rotation, which isnt what you want.

1 Like

I’m not sure you understand. Lets say the piece’s orientation to begin with is 0,0,0. Then we change it’s CFrame to the other location. It is now facing 0,90,0. Now, we multiply the 0,90,0 rotation with the original rotation and we get 0,90,0 when we want 0,0,0.

1 Like

I think this actually would work the best :smile:

local originalrotation = Piece.Orientation
Piece.CFrame = CFrame.new(DesiredPart.CFrame.X, Piece.CFrame.Y, DesiredPart.CFrame.Z)
Piece.Orientation = originalorientation

1 Like

Thats… not how a position change works
As the OP is calculating the Position by taking the new CFrame value, the new CFrame will come with a already set Rotation, so in order to get a position only, we must seperate the Position and Rotational values, in which case the rotation becomes its own Variable, and we take the new Vector3 position, and then multiply it with the old Rotation.

This is why we take the Vector3 position, convert it to a CFrame value, and then multipliy the old Rotation CFrame to get the new result, as othwerise it will cause errors.
The convertted value will have a Rotation of 0, 0, 0, but no matter what value it is, it must maintain the old rotation, so we apply the old rotation in as well for the case that its some other rotation as mentioned. This effectively killing two birds with one stone.

This isnt to say your solution is wrong, its just that it can be done in a shorter, albeit slightly different way

1 Like

Oh wait. I get it now! I was confused. Sorry!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.