Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- -- Wait for workspace to load
- wait(1)
- -- Safe object finding with error handling
- local function findObjectWithDebug(path)
- local current = workspace
- for _, name in ipairs(path) do
- current = current:FindFirstChild(name)
- if not current then
- warn("Could not find: " .. name .. " in path: " .. table.concat(path, "."))
- return nil
- end
- end
- return current
- end
- -- Try to find the trajectory guide
- local HitTrajectory
- local Table1 = workspace:FindFirstChild("Tables")
- if Table1 then
- Table1 = Table1:FindFirstChild("Table1")
- if Table1 then
- local Guides = Table1:FindFirstChild("Guides")
- if Guides then
- HitTrajectory = Guides:FindFirstChild("HitTrajectory")
- end
- end
- end
- -- If not found, create a test trajectory guide
- if not HitTrajectory then
- warn("HitTrajectory not found in expected location. Creating test guide...")
- -- Create test objects
- local testFolder = Instance.new("Folder")
- testFolder.Name = "TestTrajectory"
- testFolder.Parent = workspace
- HitTrajectory = Instance.new("Part")
- HitTrajectory.Name = "HitTrajectory"
- HitTrajectory.Size = Vector3.new(1, 1, 1)
- HitTrajectory.Position = Vector3.new(0, 5, 0)
- HitTrajectory.Anchored = true
- HitTrajectory.CanCollide = false
- HitTrajectory.Transparency = 0.5
- HitTrajectory.BrickColor = BrickColor.new("Bright red")
- HitTrajectory.Parent = testFolder
- -- Make it move for testing
- local connection
- local startTime = tick()
- connection = RunService.Heartbeat:Connect(function()
- local time = tick() - startTime
- HitTrajectory.Position = Vector3.new(math.sin(time) * 10, 5, math.cos(time) * 10)
- HitTrajectory.CFrame = CFrame.lookAt(HitTrajectory.Position, Vector3.new(0, 5, 0))
- end)
- end
- print("HitTrajectory found:", HitTrajectory ~= nil)
- -- Enhanced configuration
- local config = {
- maxSegments = 8,
- segmentLength = 6,
- maxBounces = 3,
- ballRadius = 1.2,
- powerMultiplier = 1.5,
- fadeIntensity = true,
- showBouncePoints = true
- }
- local trajectoryParts = {}
- local bounceMarkers = {}
- local currentPower = 1.0
- -- Material colors for visual appeal
- local colors = {
- primary = BrickColor.new("Bright green"),
- secondary = BrickColor.new("Bright blue"),
- bounce = BrickColor.new("Bright yellow"),
- fade = BrickColor.new("Dark green")
- }
- -- Create a better looking trajectory segment
- local function createTrajectorySegment(position, direction, length, alpha, isBounce)
- local part = Instance.new("Part")
- part.Size = Vector3.new(0.3, 0.3, length)
- part.CFrame = CFrame.lookAt(position, position + direction) * CFrame.new(0, 0, -length / 2)
- part.Anchored = true
- part.CanCollide = false
- part.CastShadow = false
- -- Visual customization
- local material = isBounce and Enum.Material.Neon or Enum.Material.SmoothPlastic
- part.Material = material
- local color = isBounce and colors.bounce or colors.primary
- if config.fadeIntensity then
- part.BrickColor = color
- part.Transparency = 0.2 + (alpha * 0.6)
- else
- part.BrickColor = color
- part.Transparency = 0.2
- end
- part.Parent = workspace
- return part
- end
- -- Create bounce marker
- local function createBounceMarker(position)
- if not config.showBouncePoints then return end
- local marker = Instance.new("Part")
- marker.Size = Vector3.new(1, 1, 1)
- marker.Shape = Enum.PartType.Ball
- marker.CFrame = CFrame.new(position)
- marker.BrickColor = colors.bounce
- marker.Material = Enum.Material.Neon
- marker.Anchored = true
- marker.CanCollide = false
- marker.Transparency = 0.2
- marker.Parent = workspace
- return marker
- end
- -- Clear all trajectory visuals
- local function clearTrajectory()
- for _, part in pairs(trajectoryParts) do
- if part and part.Parent then
- part:Destroy()
- end
- end
- trajectoryParts = {}
- for _, marker in pairs(bounceMarkers) do
- if marker and marker.Parent then
- marker:Destroy()
- end
- end
- bounceMarkers = {}
- end
- -- Simple trajectory calculation without complex physics
- local function calculateSimpleTrajectory(startPos, direction, power)
- local currentPos = startPos
- local currentDir = direction
- for i = 1, config.maxSegments do
- local nextPos = currentPos + currentDir * config.segmentLength * power
- -- Simple wall collision (table boundaries)
- local hit, hitPos = workspace:FindPartOnRay(Ray.new(currentPos, currentDir * config.segmentLength * power))
- if hit and hit.Name ~= "HitTrajectory" then
- -- Bounce calculation
- local normal = (hitPos - hit.Position).Unit
- currentDir = currentDir - 2 * currentDir:Dot(normal) * normal
- nextPos = hitPos + currentDir * 2
- -- Create bounce marker
- local marker = createBounceMarker(hitPos)
- table.insert(bounceMarkers, marker)
- end
- -- Create trajectory segment
- local segmentLength = (nextPos - currentPos).Magnitude
- local alpha = (i - 1) / config.maxSegments
- local segment = createTrajectorySegment(currentPos, currentDir, segmentLength, alpha, hit ~= nil)
- table.insert(trajectoryParts, segment)
- currentPos = nextPos
- -- Stop if we've hit too many things
- if hit then
- break
- end
- end
- end
- -- Main trajectory update function
- local function updateTrajectory()
- if not HitTrajectory or not HitTrajectory.Parent then
- warn("HitTrajectory is missing!")
- return
- end
- clearTrajectory()
- local startPos = HitTrajectory.Position
- local direction = HitTrajectory.CFrame.LookVector.Unit
- -- Add some upward angle for better visualization
- direction = (direction + Vector3.new(0, 0.1, 0)).Unit
- print("Updating trajectory from:", startPos, "Direction:", direction)
- -- Calculate simple trajectory
- calculateSimpleTrajectory(startPos, direction, currentPower)
- end
- -- Power control functions
- local function setPower(power)
- currentPower = math.clamp(power, 0.1, 2.0)
- print("Power set to:", currentPower)
- updateTrajectory()
- end
- -- Connect events
- if HitTrajectory then
- HitTrajectory:GetPropertyChangedSignal("CFrame"):Connect(updateTrajectory)
- print("Connected to HitTrajectory CFrame changes")
- else
- warn("Cannot connect to HitTrajectory - object not found")
- end
- -- Initial update
- wait(0.5)
- updateTrajectory()
- print("Trajectory system initialized!")
- -- Add some test controls
- local function setupTestControls()
- local player = Players.LocalPlayer
- if player then
- local playerGui = player:FindFirstChildOfClass("PlayerGui")
- if playerGui then
- -- Create test screen GUI
- local screenGui = Instance.new("ScreenGui")
- screenGui.Name = "TrajectoryTestGui"
- screenGui.Parent = playerGui
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(0, 200, 0, 120)
- frame.Position = UDim2.new(0, 10, 0, 10)
- frame.BackgroundColor3 = Color3.new(0, 0, 0)
- frame.BackgroundTransparency = 0.3
- frame.Parent = screenGui
- local powerLabel = Instance.new("TextLabel")
- powerLabel.Size = UDim2.new(1, 0, 0, 30)
- powerLabel.Position = UDim2.new(0, 0, 0, 0)
- powerLabel.Text = "Power: " .. currentPower
- powerLabel.TextColor3 = Color3.new(1, 1, 1)
- powerLabel.BackgroundTransparency = 1
- powerLabel.Parent = frame
- local increaseBtn = Instance.new("TextButton")
- increaseBtn.Size = UDim2.new(1, 0, 0, 30)
- increaseBtn.Position = UDim2.new(0, 0, 0, 40)
- increaseBtn.Text = "Increase Power (E)"
- increaseBtn.TextColor3 = Color3.new(1, 1, 1)
- increaseBtn.BackgroundColor3 = Color3.new(0, 0.5, 0)
- increaseBtn.Parent = frame
- local decreaseBtn = Instance.new("TextButton")
- decreaseBtn.Size = UDim2.new(1, 0, 0, 30)
- decreaseBtn.Position = UDim2.new(0, 0, 0, 80)
- decreaseBtn.Text = "Decrease Power (Q)"
- decreaseBtn.TextColor3 = Color3.new(1, 1, 1)
- decreaseBtn.BackgroundColor3 = Color3.new(0.5, 0, 0)
- decreaseBtn.Parent = frame
- -- Button events
- increaseBtn.MouseButton1Click:Connect(function()
- setPower(currentPower + 0.2)
- powerLabel.Text = "Power: " .. math.floor(currentPower * 10) / 10
- end)
- decreaseBtn.MouseButton1Click:Connect(function()
- setPower(currentPower - 0.2)
- powerLabel.Text = "Power: " .. math.floor(currentPower * 10) / 10
- end)
- -- Keyboard controls
- game:GetService("UserInputService").InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.E then
- setPower(currentPower + 0.2)
- powerLabel.Text = "Power: " .. math.floor(currentPower * 10) / 10
- elseif input.KeyCode == Enum.KeyCode.Q then
- setPower(currentPower - 0.2)
- powerLabel.Text = "Power: " .. math.floor(currentPower * 10) / 10
- end
- end)
- end
- end
- end
- -- Setup test controls
- setupTestControls()
- return {
- updateTrajectory = updateTrajectory,
- setPower = setPower,
- clearTrajectory = clearTrajectory
- }
Advertisement
Add Comment
Please, Sign In to add comment