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 5 years ago

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

01local player = game:GetService("Players").LocalPlayer
02local mouse = player:GetMouse()
03local tool = script.Parent
04 
05tool.Activated:Connect(function()
06    --Set Up
07    local bullet = Instance.new("Part")
08    --Size
09    bullet.Size = Vector3.new(0.27,0.25,1.49)
10    --Anchored
11    bullet.Anchored = true
12    --Can/Can Not Collide
13    bullet.CanCollide = false
14    --Color
15    bullet.BrickColor = BrickColor.new("Really red")
View all 32 lines...

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago
Edited 5 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

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

Using lookVector will Tween the part past the click location

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

Answer this question