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

How to make a joint rotate to a certain rad, not continuously add the rad?

Asked by 10 years ago

So i'm experimenting with this CFrame and I cant get this object to rotate to the degrees listed below, Ill explain how it works.

--Joint
script.Parent.Head.Part0 = script.Parent
script.Parent.Head.Part1 = script.Parent.Parent.Parent.Head.BasePart

--position
Head = script.Parent.Head
Head.C0 = CFrame.new( Vector3.new( 0, 2.1 , 0 ) )
--Offset
Head = script.Parent.Head
Head.C1 = CFrame.new( Vector3.new( 0 , -0.6 , 0 ) )
Head = script.Parent.Head
Head.C0 = Head.C0 * CFrame.Angles(math.rad(10),math.rad(70),math.rad(-5))

If I have Head.C0= Head.C0 * this is what happens. It takes its CFrame and continuously adds rads (10,70, -5) to the existing one. So I disable, re-enable and its 10,70,-5, I do it again and it's 20,140,-10, as long as I repeat it, thats what happens.

--Joint
script.Parent.Head.Part0 = script.Parent
script.Parent.Head.Part1 = script.Parent.Parent.Parent.Head.BasePart

--position
Head = script.Parent.Head
Head.C0 = CFrame.new( Vector3.new( 0, 2.1 , 0 ) )
--Offset
Head = script.Parent.Head
Head.C1 = CFrame.new( Vector3.new( 0 , -0.6 , 0 ) )
Head = script.Parent.Head
Head.C0 = Head.C0 * CFrame.Angles(math.rad(10),math.rad(70),math.rad(-5))

If I have Head.C0= Without the Head.C0 it always stays at 10,70,-5, (which I want). But it's not in the position I want it to be .-. Help please?

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

I'm not sure if I understand the question exactly, but I believe it's this:

You have three angles describing a rotation CFrame that you want the Head.C0 to have. You also have a position that you want the Head.C0 to have.

In that case, it's actually really simple. If rotation is defined

CFrame.Angles( math.rad(10), math.rad(70), math.rad(-5) )

then it is a CFrame that has a posiiton (p property) at the origin.

To get that particular rotation to the position we want (Head.C0.p) we can just add the position to it:

Head.C0 =
    CFrame.Angles(math.rad(10),math.rad(70),math.rad(-5) ) + Head.C0.p
-- Where `Head.Position` is any Vector3 that you want, if you want
-- it to move to particular spot
-- (using Head.Position will keep it in the same spot)





EDITED: Originally I used Head.Position, which doesn't make sense since Head is a snap.

What I meant was the position (.p) component of Head.C0, and the script is now updated to reflect that.

0
I forgot to mention, head is a Motor6d object so it has no position property. And if I pick the parts position, it'll bring it to some random spot. Orlando777 315 — 10y
0
Sorry about that -- I wasn't thinking. I edited it to use `Head.C0.p`, which is the position component of `C0`, which I believe is what is wanted. BlueTaslem 18071 — 10y
Ad

Answer this question