How would I go about making a bicycle jump? I’ve tried the following, where I already have a VectorForce controlling the forward movement of the bike. However, I’m unsure if a VectorForce is appropriate for making it jump, and I can’t think of alternative ways. This is what I’ve got and I’ve basically hit a brick wall in my brain from here. Any help is appreciated, thanks.
local HoldingSpace = false
local Jumping = false
function JumpChanged()
while HoldingSpace do
if not Jumping then
Jumping = true
Force.Force = Vector3.new(Force.Force.X, 1000, Force.Force.Z) -- increase the Y force by 1000
repeat task.wait() until PlayerHasFinishedJumpAndIsBackOnTheGround -- dont know how to detect once the player is back on the ground
Jumping = false -- player is on the ground! let us jump again!
end
end
end
UserInputService.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.Space then
HoldingSpace = true
JumpChanged()
end
end)
UserInputService.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.Space then
HoldingSpace = false
end
end)
local UserInputService = game:GetService("UserInputService")
local HoldingSpace = false
local Jumping = false
local function isPlayerOnTheGround()
return false
end
local function JumpChanged()
while HoldingSpace do
if not Jumping then
Jumping = true
Force.Force = Vector3.new(Force.Force.X, 1000, Force.Force.Z)
repeat
task.wait(0.1)
until isPlayerOnTheGround()
Jumping = false
else
task.wait(0.1)
end
end
end
UserInputService.InputBegan:Connect(function(Key, Processed)
if not Processed and Key.KeyCode == Enum.KeyCode.Space then
HoldingSpace = true
JumpChanged()
end
end)
UserInputService.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.Space then
HoldingSpace = false
end
end)
The question I’m asking is how would I detect if the player is on the ground? I don’t understand, you just copy and pasted my original script and added a function?
Apologies for the delayed response. I tried using this and I think that ApplyImpulse applies a better jumping effect since it is more instant, and it feels more natural than LinearVelocity. Besides this, even with the linear velocity, the bicycle still tips forward as shown in the video, which is what I’m now trying to solve
I made the Player massless and made sure the force was being applied to the center of mass as I was applying it to only the center of the model. It works fine, but whenever the bike is in motion, it will tip forward again. It only happens a bit when I release the W key before jumping, but it happens often if I am still holding W after the jump. I also can’t make the Player massless permanently, because that interfere with other scripts that need the character’s mass, so I am still looking for an alternative solution
I am also looking for ways to make the bicycle stop bouncing when it reaches the ground after a jump. I want it to land perfectly and stop moving
I don’t know if my bike is setup in the same way that the one shown in the top videos is, but it’s all I could think of how a bike would be setup. Here is a link to the scripts shown under Drive. I used them from a pre-existing model since I don’t know how to do it myself, and it would be too time-consuming.
You can fix the bouncing by making the Wheels’s CustomPhysicalProperties Elasticity to 0 and ElasticityWeight to 100
About the tilting forward when jumping, I’m pretty sure it occurs because the VectorForce applies the force above the bike’s center of mass which causes the bike to tilt, even if u turn on VectorForce’s ApplyAtCenterOfMass property, it will apply the force at the bike assembly’s center of mass which does not include the wheels, this is because the assembly only includes parts that are rigidly connected with joints like WeldConstraint, RigidConstraint, Weld, Motor, Motor6D and other rigid joints, but not constraints like HingeConstraint, BallSocketConstraint, PrismaticConstraint, etc
You can fix the tilting by turning off the VectorForce’s ApplyAtCenterOfMass property and putting the attachment at the center of mass of the whole bike, the easiest way to do this is probably with a script that automatically calculates the center of mass and puts the attachment where it needs to be
local Model = Script.Parent -- put the reference to your bike into this variable
local VectorForce = Model.Drive.VectorForce -- put the reference to the vector force of your bike into this variable
local CenterOfMass = Vector3.zero
local TotalMass = 0
for _, v in pairs(Model:GetDescendants()) do
if v:IsA("BasePart") then
CenterOfMass += v.Mass * v.CFrame:PointToWorldSpace(v.CenterOfMass)
TotalMass += v.Mass
end
end
CenterOfMass /= TotalMass
VectorForce.Attachment0.WorldPosition = CenterOfMass