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

How to tween in a certain direction?

Asked by 4 years ago

Here is my code for a gun I want to tween the bullet to where it is facing. Anybody know how?

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent

tool.Activated:Connect(function()
    --Set Up
    local bullet = Instance.new("Part")
    --Size
    bullet.Size = Vector3.new(0.27,0.25,1.49)
    --Anchored
    bullet.Anchored = true
    --Can/Can Not Collide
    bullet.CanCollide = false
    --Color
    bullet.BrickColor = BrickColor.new("Really red")
    --Matirial
    bullet.Material = Enum.Material.Neon
    --Parent
    bullet.Parent = workspace
    --Positon
    bullet.Position = tool.Handle.Position + Vector3.new(0,0.5,0)
    --Angle
    bullet.CFrame = CFrame.new(bullet.CFrame.p, mouse.Hit.p)

    --Movement
    local TweenService = game:GetService("TweenService")

    local info = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

    TweenService:Create(bullet, info, {Position = bullet.Position + Vector3.new(0,0,100)}):Play()

end)

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You've already adjusted the end Angle and start Position, so now you just want the Tween to end where ever your mouse clicked. This is Local, so other players won't see it, your next challenge will be working with RemoteEvents to notify the server and other players of your bullet.

Using mouse.Hit will Tween the part to the mouse CFrame

 local info = TweenInfo.new(.15, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
TweenService:Create(bullet, info, {CFrame = mouse.Hit}):Play()

Using lookVector will Tween the part past the click location

 local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
TweenService:Create(bullet, info, {Position = bullet.CFrame.lookVector * 500 }):Play()
0
Thanks aandmprogameing 52 — 4y
Ad

Answer this question