Launch Pad Scripting

I have a car, and I am having trouble making a pad that launches it far.

I want it to be like mario kart. I have tried using all the body movers, but nothing has worked to my liking. Some have worked, such as body position, but it only goes in one direction. Is there a way I can make this move according to the seat orientation or CFrame?

Here is my script:

script.Parent.Touched:Connect(function(hit)
	if hit.Name == "FL"then
		if not hit.Parent.Parent.DriveSeat:FindFirstChild("BodyGyro")then
			local new = Instance.new("BodyGyro", hit.Parent.Parent.DriveSeat)
			
			--new.Force = Vector3.new(1000,1000,1000)
			--new.Location = hit.Parent.Parent.DriveSeat.Position
			
			new.CFrame = hit.Parent.Parent.DriveSeat.CFrame
		end
	end
end)

You almost have it. You can use a BodyPosition | Roblox Creator Documentation, like you said. However, this doesn’t use the assemblies local directions when moving it. To account for this you will have to continually update it’s direction to the direction you want to go in.

However, the legacy BodyMover's have all (mostly) been superseded by newer body movers. In this case you can try learning about and using the VectorForce | Roblox Creator Documentation body mover. It accounts for some needs like this, is just as easy (if not easier) to use, and give you more control over the force applied to the object without having to script the intended behavior yourself. To set up such a system like a launch pad for a go-kart I would do something like this:

  1. Create an Attachment | Roblox Creator Documentation in the Model | Roblox Creator Documentation (I’m guessing it’s grouped in a model) of the go-kart (in this case I’m guessing you want this to be the DriveSeat, although it’d be best to set it to the chassis of the go-kart)
  2. Move this attachment to where you want the force applied to on the go-kart. This step is necessary if you want the power applied to the back wheels or front wheels. Otherwise you can set it’s position to somewhere in-between or just set the VectorForce | Roblox Creator Documentation to true.
  3. Create a VectorForce object in the PrimaryPart and set it’s Constraint | Roblox Creator Documentation to the previously created attachment. Also make sure the VectorForce | Roblox Creator Documentation property is relative to Attachment0. Then set the VectorForce | Roblox Creator Documentation property to the Vector3 | Roblox Creator Documentation relative direction you want the force to be applied in. Since the force should be relative to the go-kart, you only have to set it once. You an also rename it to “Boost” or something.
  4. When the go-kart drives over the launch pad, check if the Constraint | Roblox Creator Documentation is enabled. If it isn’t, then set it to true. You can then wait a certain amount of time and then switch it back to disabled.

For step number 4 the launch pad script can look something like this:

local touched = {} -- array to cache already-touched parts -- this is basically a security blanket

LaunchPart.Touched:Connect(function(hit)
	if (hit.Name == "FL") and not table.find(touched, hit) then
		table.insert(touched, hit)


		local boost = hit.Parent.Parent.DriveSeat:FindFirstChild("VectorForce")
		
		if not boost.Enabled then
			boost.Enabled = true
			task.wait(2) -- custom delay for how long you want the boost to last
			boost.Enabled = false

			table.remove(touched, table.find(touched, hit)) -- we have to find the position of the part in the table again because it may have updated from other entries being removed
		end
	end
end)
P.S.

I noticed in your code you used the parent parameter for the Instance.new constructor.

While this is not necessarily a bad thing to do, it can affect performance, especially when you are creating many objects at once. You can read this post that explains why.

1 Like

Wow, thank you so much. It really looks like you spent a lot of time on this post. I have a couple questions though.

  1. How does task.wait() work, how is it different than just wait(), and is there different “tasks”, and could I get a link to a post/documentation on tasks?

  2. I had to change “if not boost.Enabled then” to “if boost.Enabled == false then” for it to work. Why does this happen?

Sure thing! I love helping others on the forums.

To answer question #1, here’s the announcement about the task library.

You can also look at the documentation for the task | Roblox Creator Documentation library if you want. I can’t say anything more on the subject because then I’d just be repeating what’s explained in the post.

#2: I just now tested this and I have not experienced this problem like you have. Is the VectorForce.Enabled property set to false by default? Did you make any alterations to the code I provided that could have caused this? If so, what were they?

No alterations except the one alteration on the if statement. VectorForce.Enabled was set to true by default, so I made it false so it isn’t always on.

Thanks for the task library announcement!

I would try testing the code again with the not boost.Enabled part, but add print(boost.Enabled) on the line before that. If it prints the value as false and doesn’t boost then you may have a bug. If you can’t find any other reason that this is happening, then I recommend you send a message to the Bug support - DevForum | Roblox group.

Huh. For some reason it works now lol. Thanks for all your help!