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

Cframe to velocity?

Asked by 8 years ago

So could someone help me convert this p.CFrame = p.CFrame * CFrame.new(Vector3.new(0, -4, 0)) to velocity that moves at the same speed as -4? I need to convert it to velocity because I heard I can't detect if the part touches something when it's getting cframed.

2 answers

Log in to vote
0
Answered by 8 years ago

Well, if you did this:

p.CFrame = p.CFrame * CFrame.new(Vector3.new(0, -4, 0))

it would immediately move it down 4 studs, but if you used velocity, it would gradually move down. I'm assuming you would prefer the latter; in that case, you would use a for loop:

for i = 1, 10 do -- Change the 10 to how much you want the part to move down.  10 will move it down 1 stud.
    p.CFrame = p.CFrame * CFrame.new(Vector3.new(0, -0.1, 0))
    wait(0.1) -- Change the 0.1 to how fast you want it to go down.
end

That way, you don't need velocity. And yes, you can check for Touched events.

Ad
Log in to vote
0
Answered by 8 years ago
p.CFrame = p.CFrame * CFrame.new(Vector3.new(0, -4, 0))

Was taken from a for loop here's the full code

for i = 1 , 150 do
        d.Transparency = d.Transparency + 0
        d.CFrame = d.CFrame * CFrame.new(Vector3.new(0, -2, 0))
        p.CFrame = p.CFrame * CFrame.new(Vector3.new(0, -4, 0))
        m.Scale = m.Scale - Vector3.new(0, 0.02, 0)
        wait()
end 

Also this script is cloned into p and it doesn't work so that's why I thought I need to change it to velocity, why won't this script work?

arrow = script.Parent
damage = 4

function onTouched(hit)


    humanoid = hit.Parent:findFirstChild("Humanoid")
    if humanoid~=nil then
        humanoid.Health = humanoid.Health - damage
        wait()
    end
    if hit.Name == "Blast" or hit.Name == "BasePlate" then
        Effect = Instance.new("Part")
        Effect.Parent = game.Workspace
        Effect.Anchored = true
        Effect.CanCollide = false
        Effect.Size = Vector3.new(1, 1, 1)
        Effect.formFactor = "Symmetric"
        Effect.Transparency = 0
        Effect.BrickColor = BrickColor.new("Institutional white")
        Effect.TopSurface = "Smooth"
        Effect.BottomSurface = "Smooth"
        EffectMesh = Instance.new("SpecialMesh")
        EffectMesh.Parent = Effect
        EffectMesh.MeshType = "Sphere"
        EffectMesh.Scale = Vector3.new(1, 1, 1)
        for i = 1 , 20 do
        Effect.CFrame = CFrame.new(hit.Position)
        EffectMesh.Scale = EffectMesh.Scale + Vector3.new(1, 1, 1)
        wait()
        end
        wait()
    end
end

arrow.Touched:connect(onTouched)
0
Just as I thought, found this in Roblox wiki "This event does not fire if the part is being CFramed through something." therefore I need to use velocity to use Touched :/ could you help me change it to velocity? EradicateTheNoobs 0 — 8y

Answer this question