Is there a way to treat character as a homing missile? I know how to move it to a part but the jumping is what got me, I’m trying to make the player jump in a curve/arc but couldn’t figure out a way.
local Player = game:GetService("Players").LocalPlayer
local userInput = game:GetService("UserInputService")
local Mouse = {}
local RAY_DISTANCE = 1000
local cam = workspace.CurrentCamera
function Mouse.HitPosition(raycastParams, distance)
local mousePos = userInput:GetMouseLocation()
local viewportMouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
local rayCastResult = workspace:Raycast(viewportMouseRay.Origin, viewportMouseRay.Direction * (distance or RAY_DISTANCE), raycastParams)
local hitPosition
if rayCastResult then
hitPosition = rayCastResult.Position
else
hitPosition = viewportMouseRay.Origin+viewportMouseRay.Direction * (distance or RAY_DISTANCE)
end
return hitPosition
end
Player:GetMouse().Button1Down:Connect(function()
local raycastP = RaycastParams.new()
raycastP.FilterDescendantsInstances = {Player.Character}
raycastP.FilterType = Enum.RaycastFilterType.Exclude
local hrp : BasePart = Player.Character.HumanoidRootPart
local t = Instance.new("Part")
t.Anchored = true
t.CanCollide = false
t.Color = Color3.fromRGB(255,0,0)
t.Material = Enum.Material.Neon
t.Position = Mouse.HitPosition(raycastP)
t.Parent = workspace
local humanoid : Humanoid = Player.Character.Humanoid
humanoid.JumpPower = 90
humanoid:MoveTo(t.Position, t)
humanoid.Jump = true
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end)
So, I found a way, but it can be very tricky, as it requires you to create a cooldown for the jumps. I based this script in your first and this was the result:
here is the code lol
local Player = game:GetService("Players").LocalPlayer
local userInput = game:GetService("UserInputService")
local Mouse = {}
local RAY_DISTANCE = 1000
local cam = workspace.CurrentCamera
function Mouse.HitPosition(raycastParams, distance)
local mousePos = userInput:GetMouseLocation()
local viewportMouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
local rayCastResult = workspace:Raycast(viewportMouseRay.Origin, viewportMouseRay.Direction * (distance or RAY_DISTANCE), raycastParams)
local hitPosition
if rayCastResult then
hitPosition = rayCastResult.Position
else
hitPosition = viewportMouseRay.Origin+viewportMouseRay.Direction * (distance or RAY_DISTANCE)
end
return hitPosition
end
local function QuadraticBezier(t,p0,p1,p2)
return (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2;
end
Player:GetMouse().Button1Down:Connect(function()
local raycastP = RaycastParams.new()
raycastP.FilterDescendantsInstances = {Player.Character}
raycastP.FilterType = Enum.RaycastFilterType.Exclude
local hrp : BasePart = Player.Character.HumanoidRootPart
local t = Instance.new("Part")
t.Anchored = true
t.CanCollide = false
t.Color = Color3.fromRGB(255,0,0)
t.Material = Enum.Material.Neon
t.Position = Mouse.HitPosition(raycastP)
t.Parent = workspace
local pos2 = t.Position
local pos1 = hrp.Position
local distance = (pos1 - pos2).Magnitude
local center = pos1:Lerp(pos2, 0.5)
center = center+Vector3.new(0,distance/1.5,0)
local t1 = Instance.new("Part")
t1.Anchored = true
t1.CanCollide = false
t1.Color = Color3.fromRGB(255,0,0)
t1.Material = Enum.Material.Neon
t1.Position = center+Vector3.new(0,distance/1.5,0)
t1.Parent = workspace
t1.Name = "testpart"
for i = 0, 1, 0.01 do
local targetPosition = QuadraticBezier(i, pos1, center, pos2)
hrp.CFrame = CFrame.new(targetPosition)
task.wait()
end
end)
That’s pretty cool, I added facing the mouse direction while jumping…
local Player = game:GetService("Players").LocalPlayer
local userInput = game:GetService("UserInputService")
local Mouse = {}
local RAY_DISTANCE = 1000
local cam = workspace.CurrentCamera
function Mouse.HitPosition(raycastParams, distance)
local mousePos = userInput:GetMouseLocation()
local viewportMouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
local rayCastResult = workspace:Raycast(viewportMouseRay.Origin, viewportMouseRay.Direction * (distance or RAY_DISTANCE), raycastParams)
local hitPosition
if rayCastResult then
hitPosition = rayCastResult.Position
else
hitPosition = viewportMouseRay.Origin + viewportMouseRay.Direction * (distance or RAY_DISTANCE)
end
return hitPosition
end
local function QuadraticBezier(t,p0,p1,p2)
return (1-t)^2*p0 + 2*(1-t)*t*p1 + t^2*p2
end
Player:GetMouse().Button1Down:Connect(function()
local raycastP = RaycastParams.new()
raycastP.FilterDescendantsInstances = {Player.Character}
raycastP.FilterType = Enum.RaycastFilterType.Exclude
local hrp : BasePart = Player.Character.HumanoidRootPart
local t = Instance.new("Part")
t.Anchored = true
t.CanCollide = false
t.Color = Color3.fromRGB(255,0,0)
t.Material = Enum.Material.Neon
t.Position = Mouse.HitPosition(raycastP)
t.Parent = workspace
local pos2 = t.Position
local pos1 = hrp.Position
local distance = (pos1 - pos2).Magnitude
local center = pos1:Lerp(pos2, 0.5)
center = center + Vector3.new(0, distance / 1.5, 0)
local t1 = Instance.new("Part")
t1.Anchored = true
t1.CanCollide = false
t1.Color = Color3.fromRGB(255,0,0)
t1.Material = Enum.Material.Neon
t1.Position = center + Vector3.new(0, distance / 1.5, 0)
t1.Parent = workspace
t1.Name = "testpart"
for i = 0, 1, 0.01 do
local targetPosition = QuadraticBezier(i, pos1, center, pos2)
hrp.CFrame = CFrame.new(targetPosition)
local lookAtPos = Mouse.HitPosition(raycastP) -- Update look direction
hrp.CFrame = CFrame.new(targetPosition, Vector3.new(lookAtPos.X, targetPosition.Y, lookAtPos.Z)) -- Face the target
task.wait()
end
end)
local center = pos1:Lerp(pos2, 0.5)
center = center + Vector3.new(0, distance / 2, 0) --jump height
local speed = 0.005 --jump speed
local t1 = Instance.new("Part")
t1.Anchored = true
t1.CanCollide = false
t1.Color = Color3.fromRGB(255,0,0)
t1.Material = Enum.Material.Neon
t1.Position = center + Vector3.new(0, distance / 2, 0)
t1.Parent = workspace
t1.Name = "testpart"
for i = 0, 1, speed do
local targetPosition = QuadraticBezier(i, pos1, center, pos2)
hrp.CFrame = CFrame.new(targetPosition, pos2)
task.wait()
end
end)
It’s a bit shaky on them landings (needs work) and needs a debounce set to the whole thing until landed. May even be able to switch animation to a more missile like stance or possibly Humanoid.Platform Stand. Kakazin19010 post is a good start.