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

How would I move a welded object in one axis while the other is moving?

Asked by
Nootian 184
4 years ago

Explanation

Imagine you have a moving cube, it is rotating in all axis and moving every second, but, if you weld a sphere hovering 4 studs above it, the rotation of the cube will be relative to it, so the sphere will also be rotating just like the cube, and moving in a radius of 4 studs.

Goal

I want the sphere to stay in the same position above the cube

Attempt

01cube = workspace.cube
02sphere = workspace.sphere
03 
04Weld = Instance.new("Weld")
05Weld.Parent = cube
06Weld.Part1 = sphere
07Weld.Part0 = cube
08 
09Height = 4
10 
11while wait() do
12    Weld.C0 = cube.CFrame:Inverse() * sphere.CFrame * CFrame.new(0,Height,0)
13end

Pre-Solution

The idea that I had was to get the position of the cube, add the height, then turn it into a relative CFrame.

1--How to find relative:
2cube.CFrame:Inverse() * sphere.CFrame

1 answer

Log in to vote
1
Answered by 4 years ago

This is a pretty complicated solution so it might not work right away but I had a situation similar to this one day when i was messing around and it was for a ball with a click detector that i needed it to start going up and to the left when i clicked the way i ended up doing it was using body velocity and making a child to a part i had created in the same script to do this i used

1local children = Instance.new("BodyVelocity", Part)

to make the body velocity (it was a bit ganky at first but ended up working

the problem i ran into was that it was set to going up but i needed it to go up and to the left so i had to set the body velocity's x, y, z velocity to new values

i did this by putting right under it

1children.Velocity = Vector3.new(-10,10,0)

and IT WORKED

so with my new found knowledge i used it to do the childish thing of making a noob start pissing into the sky the final code was

01local Click = script.Parent
02local brick = script.Parent.Parent
03 
04Parts = {}
05 
06function whenMouseClick()
07    for count = 1, 50 do
08        Parts[count] = Instance.new("Part",game.Workspace.AnthonysPlayground)
09        Parts[count].Name = "Piss"..count
10        Parts[count].Color = Color3.fromRGB(164,168,50)
11        Parts[count].Shape = Enum.PartType.Ball
12        Parts[count].Size = Vector3.new(0.5,0.5,0.5)
13        Parts[count].Position = brick.Position + Vector3.new(10, 1, 0)
14        local children = Instance.new("BodyVelocity", Parts[count])
15 
View all 22 lines...

and it turned out pretty funny Hope i helped and good luck on your project!

0
Thanks for awnsering :D Nootian 184 — 4y
Ad

Answer this question