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
3 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

cube = workspace.cube
sphere = workspace.sphere

Weld = Instance.new("Weld")
Weld.Parent = cube
Weld.Part1 = sphere
Weld.Part0 = cube

Height = 4

while wait() do
    Weld.C0 = cube.CFrame:Inverse() * sphere.CFrame * CFrame.new(0,Height,0)
end

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.

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


1 answer

Log in to vote
1
Answered by 3 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

        local 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

        children.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

local Click = script.Parent
local brick = script.Parent.Parent

Parts = {}

function whenMouseClick()
    for count = 1, 50 do
        Parts[count] = Instance.new("Part",game.Workspace.AnthonysPlayground)
        Parts[count].Name = "Piss"..count
        Parts[count].Color = Color3.fromRGB(164,168,50) 
        Parts[count].Shape = Enum.PartType.Ball
        Parts[count].Size = Vector3.new(0.5,0.5,0.5)
        Parts[count].Position = brick.Position + Vector3.new(10, 1, 0)
        local children = Instance.new("BodyVelocity", Parts[count])

        children.Velocity = Vector3.new(-10,10,0)
        print(Parts[count].Name)
        wait(0.1)
    end
end

Click.MouseClick:connect(whenMouseClick)

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

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

Answer this question