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

Rotating an object proportional to another object?

Asked by 8 years ago

--WARNING-- Lots of math involved!

So I've been playing around with roblox and math equations, and I have a problem. I'm trying to rotate a part, so that it points to another part. I don't have much code written yet, and not much of a plan, so bear with me please! Below I have a list of steps that I want to use in the script to to figure out the rotation the part needs to be at:

1) I want to compare the two positions using the slope

2) I will next find the rotation value (the object will have), proportional to the slope.

3) Before I set the final rotation for that part, I want to make sure that the rotation isn't the opposite of what it should be

*Note I'm that very good at CFraming, so I usually use rotations instead. If you answer my question, please put the rotation values into rotations, not CFrame's.

I'm starting to get the first step down (though I don't have written the script yet), but the rest seems complex and time consuming. Anyways, if you have a solution to this problem, I'd like it to be in a certain format and having certain details:

1) All math operations for each step must be in separate functions.

2) Only write the bare minimum of code for the whole operation (no fancy dancy debugging operations or extremely complex code)

3) Please explain each operation for each step in a way that I can understand (english please!)

That's pretty much all I have to say for now. If you have any questions, comments, or suggestions, post a comment/answer below and I'll get right on - top of it ASAP! Thanks for the help!!!!!!

0
Part1.CFrame=CFrame.new(Part1.Position,Part2.Position) 1waffle1 2908 — 8y
0
Please put this into an answer. I want closure for my questions! LateralLace 297 — 8y

1 answer

Log in to vote
0
Answered by
Scriptecx 124
8 years ago

CFrame.new has a second parameter that lets you rotate the object to point to a certain position.

Lets say there was a part in the workspace named Part1, and we wanted to rotate that part to point to a part in the workspace named Part2.

We would simply do this:

game.Workspace.Part1.CFrame = CFrame.new (Part1.Position, Part2.Position)

We are keeping the Part1 in the same position, and making it look at Part2's position.

0
Well I did try to discourage CFraming... OH WELL, guess this is a good time to learn more about it. THX!!! LateralLace 297 — 8y
Ad

Answer this question