Hello, so I am trying to make a ball that glides in a direction that the player is looking when the player clicks the ball. I have it currently so the ball teleports to the location but I do not know how to add a nice gliding animation. This is the code I have currently that lets the ball teleport
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("dodgeBall")
local tool = script.Parent
local toolHandle = tool.Handle
local Player = game.Players.LocalPlayer
Remote.OnServerEvent:Connect(function(player)
local Character = player.Character
local RootPart = Character:WaitForChild("HumanoidRootPart")
local offset = Vector3.new(5, 0, -30)
tool.Parent = game.Workspace
tool = game.Workspace.Tool
toolHandle.CFrame = RootPart.CFrame * CFrame.new(offset)
end)
I was in the process of trying to add a tween effect, but I am not sure if I can make that work with what I am trying to do. To make this possible should I use a body mover, tweening, or something else? I am not sure if using CFrame is the correct way to do this since it kind of just makes the ball teleport, but I just wanted to see if anybody could help me first before I continue lol.
I suggest using things like BodyForces and the simple Velocity vector. Seeing as Roblox’s physics is well optimised, you should to take advantage of it when trying to create motion. You’ll have to do some mathematics to do with slowing the ball down by using these techniques (Newton’s First Law of Motion would be the easiest, as well as the elementary physics equations of motion [SUVAT]) which might be more effort than it’s worth but try giving it a go.
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("dodgeBall")
local tool = script.Parent
local toolHandle = tool.Handle
local Player = game.Players.LocalPlayer
Remote.OnServerEvent:Connect(function(player)
local Character = player.Character
local RootPart = Character:WaitForChild("HumanoidRootPart")
local offset = Vector3.new(5, 0, -30)
tool.Parent = game.Workspace
tool = game.Workspace.Tool
local tweenInfo = TweenInfo.new(SetYourProperties)
local goal = {}
goal.CFrame = RootPart.CFrame * CFrame.new(offset)
local tween = TweenService.Create(toolHandle, tweenInfo, goal)
tween:Play()