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

Moving a projectile with a curve?

Asked by 3 years ago
Edited 3 years ago

I want to make it travel at a slight curve, see the image attached, and in the direction which it is facing, I don't know how to do that can someone help me?

I got it to do the curve I wanted, but it only goes in one direction https://gyazo.com/b9ae87b361d0b2c909f7d03e87b8d048

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
    local f = game.ReplicatedStorage.Flare:Clone()
    f.Parent = workspace
    f.CFrame = script.Parent.Parent:WaitForChild("HumanoidRootPart").CFrame + Vector3.new(0,5,0)
end)

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

This is messy because you're using CFrame and Position and Orientation. This is not needed because CFrame is position and orientation.

local mouse = game.Players.LocalPlayer:GetMouse()
local TweenService = game:GetService("TweenService")

local goal = {}
goal.Position = Vector3.new(f.CFrame.upVector*250 + f.CFrame.lookVector*500)

local tweenInfo = TweenInfo.new(
    3, -- Time it takes to tween (I think)
    Enum.EasingStyle.Linear, -- EasingStyle
    Enum.EasingDirection.Out, -- EasingDirection
    0, -- RepeatCount (when less than zero the tween will loop indefinitely)
    false, -- Reverses (tween will reverse once reaching it's goal)
    0 -- DelayTime
)

mouse.Button1Down:Connect(function()
    local humanoidrootpart = script.Parent.Parent:WaitForChild("HumanoidRootPart")
    local f = game.ReplicatedStorage.Flare:Clone()
    f.Parent = workspace
    f.CFrame = CFrame.new(humanoidrootpart.Position,humanoidrootpart.Position) +
Vector3.new(0,5,0)

    TweenService:Create(f,tweenInfo,goal) -- Try this, it goes up 250 studs and forward 500 studs in 3 seconds

end)

Note: This might not fix it, it just makes it cleaner. Edit: You can achieve what you want to do with tween service I believe.

0
Thank you, it looks a lot nicer to look at now Hex_0517 10 — 3y
0
Also, what exactly is the issue, I couldn't understand your original post very well. CosmicIsGod 139 — 3y
0
If there isn't an issue what do you want to achieve CosmicIsGod 139 — 3y
0
Right now it spawns in were i want it to, i was it to go up 250 studs and forward 500 studs, creating the arc, from where the player is facing Hex_0517 10 — 3y
View all comments (6 more)
0
can you potentially tween it? CosmicIsGod 139 — 3y
0
I tried that but i just cant seem to get it right Hex_0517 10 — 3y
0
I changed the code try it CosmicIsGod 139 — 3y
0
I got "Uable to cast to Dictionary" Which is what i got earlier also Hex_0517 10 — 3y
0
Try now CosmicIsGod 139 — 3y
0
Now its just not tweening, i can mess with it and try to get it to fix Hex_0517 10 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

So i got it to work, doesnt look how i want it to so ima mess with it more, but here is the code

local mouse = game.Players.LocalPlayer:GetMouse()
local TweenService = game:GetService("TweenService")

mouse.Button1Down:Connect(function()
    local f = game.ReplicatedStorage.Flare:Clone()
    local humanoidrootpart = script.Parent.Parent:WaitForChild("HumanoidRootPart")
    f.Parent = workspace
    local goal = {}
    f.Orientation = humanoidrootpart.Orientation
    f.Position = humanoidrootpart.Position
    goal.Position = f.CFrame.LookVector * 500 + f.CFrame.UpVector * 250

    local tweenInfo = TweenInfo.new(
        3, -- Time it takes to tween (I think)
        Enum.EasingStyle.Linear, -- EasingStyle
        Enum.EasingDirection.Out, -- EasingDirection
        0, -- RepeatCount (when less than zero the tween will loop indefinitely)
        false, -- Reverses (tween will reverse once reaching it's goal)
        0 -- DelayTime
    )



    local tween = TweenService:Create(f,tweenInfo,goal) -- Try this, it goes up 250 studs and forward 500 studs in 3 seconds
    tween:Play()
    wait(2)
    f.Anchored = false
    f.Velocity = f.Velocity * 1
end)

Answer this question