I am trying to code the jump pad to make player have a planed trajectory, but would I tween the player or is this something more simple and better.
(note: I am not really I scripter so I do not know what I am doing!)
I am trying to code the jump pad to make player have a planed trajectory, but would I tween the player or is this something more simple and better.
Hey there! So, you’re trying to make a jump pad that launches the player with a planned trajectory based on the angle of the jump pad. Check this code:
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
-- Set up the jump pad part
local jumpPad = script.Parent
local jumpPadPart = jumpPad.Parent
jumpPad.Touched:Connect(function(hit)
-- Check if the hit part is a player's character
if hit.Parent:FindFirstChild("Humanoid") then
-- Get the direction and angle of the jump pad
local direction = (jumpPadPart.CFrame.lookVector * -1).unit
local angle = math.asin(direction.y)
-- Calculate the velocity based on the angle
local velocity = (50 * direction) + (Vector3.new(0, 50 * math.cos(angle), 0))
-- Apply the velocity to the player's humanoid
humanoid.Jump = true
humanoid.JumpPower = 0
humanoid.ChangeState(Enum.HumanoidStateType.Jumping)
humanoid.MoveDirection = velocity
end
end)
so what is the use of character would it just be easier to do
“local humanoid = player.Character.Humanoid”
And also can you explain how this works a little.
Right, but he needs to detect when the touchpad was touched. The issue with this code is that the OP should check if hit.Parent:FindFirstChild("Humanoid")
is equal to the local humanoid
defined in the script. Like so:
if hit.Parent:FindFirstChild("Humanoid") == humanoid then
...
So that would be on line 10? or is that wrong
Yes, that’s correct.
grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
The error is happening because you need to make the script a local script.
Wow thanks i forgot that there are different scripts. i feel stupid now, but even with that the code does not work.
JumpPadTest.rbxl (42.8 KB)
local jumpPad = script.Parent:WaitForChild("Spring")
jumpPad.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player.Character and player.Character.PrimaryPart then
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
humanoid.PlatformStand = true
character.PrimaryPart.Velocity = jumpPad.CFrame.UpVector * 100
wait(.3)
humanoid.PlatformStand = false
end
end)
Thanks, but i have a question would i change the power on line 8 and i would like to know how this works a little. I find the Solution more simple but complicating at the same time.
yes, the power would be changed at line 8
the way this works, is, it takes the ‘green’ part, and gets the ‘upvector’ of its cframe. So basically it takes whatever the green pad’s ‘up’ direction is, then it applies this vector as a Velocity to the players HumanoidRootPart.
I set the humanoid to platform standing, so there are no other physics affecting it
then I set the velocity of its primary part (HumanoidRootPart)
then .3 seconds later, I remove platform standing, so the player has physics control again
This is a very ‘crude’ and ‘basic’ way of doing this, but I felt it would give you a good starting place.
Some things to improve, might be…
Have a script in the player that if it is ever in PlatformStanding, and it hits something, it will make itself come out of platform standing.
or put the character into a ‘sitting’ position, instead of platform standing, so there is no chance of getting stuck in a platform standing pose
also you might want to play a custom animation.
Or use body movers instead of just applying the velocity.
A lot of old scripts in Roblox Gear, that rely on pushing someone or firing a projectile, will use body movers. You might look into that.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.