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

How do I Move an object along a face (and rotate it)?

Asked by 8 years ago

Basically I want to move an object left or right from where it is facing.

I've tried simply CFraming along a Z axis, but that of course only goes along the Z axis. I want the object to be able to face any direction and still move a solid left or right.

ball.CFrame = (ball.CFrame + Vector3.new(0,0,.15)) * CFrame.Angles(0,0,math.pi/24)

You might notice that its also being rotated along the Zaxis. Would there be a way to move it left or right and rotate it? Logically, it would cause the motion to form a circle, but I don't want that.

0
At least are there any Wiki articles that define the concept? randomsmileyface 375 — 8y

1 answer

Log in to vote
0
Answered by
Wizzy011 245 Moderation Voter
8 years ago

You're almost there with the CFrame, but to make sure it works every time you're going left or right, you multiply on another CFrame rather than adding a Vector3. Your Angles isn't correct also, the 3rd value would change the Z orientation which isn't your intended objective I'd assume as you're trying to turn left/right. Instead, the Y Axis should have math.pi/24 added to it

Finished off, it'd look like this:

ball.CFrame = ball.CFrame * CFrame.new(0,0,.15) * CFrame.Angles(math.pi/24,0,0)

I've only sorted turning right here, to turn left, it'd obviously just be -math.pi/24

0
Yes, you got it right that I'm trying to make it roll left and right, but I don't want it to turn that direction, so the Y axis is out. Also I don't want it to roll  to the directly to the left (or right) while I'm trying to move it another direction across the Z axis, so X axis is out too. In order to make it rotate along the direction its moving., it would require rotation along the Z-Axis.  randomsmileyface 375 — 8y
0
Rotation across the X axis does allow this thing to go straight left or right, and so does taking the angles out altogether. Yet, Rotation across Z axis will rotate it around a point in air :P. You did answer the original question so I'm grateful for that, but if you could expand a little, that would be nice. randomsmileyface 375 — 8y
0
Actually, using a little logic of my own to save the movement CFrame in a variable for editing next time, I was able to fix it. Thanks randomsmileyface 375 — 8y
Ad

Answer this question