#How do i make bounce point to camera?

1 messages · Page 1 of 1 (latest)

sullen escarp
#

So im making a new game about flinging yourself and I wanted that the direction that yuo're looking at, that direction will fling yourself, here is the code, the error is that the player flops instead of bouncing more and more:

#

ghj

#

why doesnt the script get sent

#
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camera = workspace.CurrentCamera
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local HRP = char:FindFirstChild("HumanoidRootPart")
local InputService = game:GetService("UserInputService")
local bouncing = nil
hum.StateChanged:Connect(function(oldST, newST)
#

if newST == Enum.HumanoidStateType.PlatformStanding then
        if not bouncing then 
            bouncing = RunService.Heartbeat:Connect(function(dt)
                local plyrVelocity = HRP.AssemblyLinearVelocity
                local HRPposition = HRP.Position

                local direction = plyrVelocity * dt
                local RCastP = RaycastParams.new()
                RCastP.FilterDescendantsInstances = {char}
                local result = workspace:Raycast(HRPposition, direction, RCastP)

                if result then
                    local lookDir = Vector3.new(camera.CFrame.LookVector.X, camera.CFrame.LookVector.Y, camera.CFrame.LookVector.Z)
                    local rightDir = Vector3.new(camera.CFrame.RightVector.X, 0, camera.CFrame.RightVector.Z)
                    local Nresult = result.Normal
                    local reflectedVelocity = plyrVelocity - 2 * (plyrVelocity:Dot(Nresult)) * Nresult
                    HRP.AssemblyLinearVelocity = (reflectedVelocity * 1.5)
                    HRPposition = result.Position
                    print(result)
                    print("Bounced i think")
                end
            end)
        end
        


    end

    if newST ~= Enum.HumanoidStateType.PlatformStanding and player.CharacterAdded and bouncing then
        if char == nil then return end
        if HRP == nil then return end
        local currentvelocity = HRP.AssemblyLinearVelocity
        local Xvel = currentvelocity.X
        local Zvel = currentvelocity.Z
        local Yvel = currentvelocity.Y
        HRP.AssemblyLinearVelocity = Vector3.new(Xvel, -Yvel * 3, Zvel)
        bouncing:Disconnect()
        bouncing = nil

    end
end)
rigid shadow
#

Your script is flopping because it reflects the player’s current velocity instead of launching them in the camera’s look direction, and some variables are being used before they’re properly defined.