Making a Trampoline
Making a Trampoline
This tutorial has been split up into two different methods, the first is the building method. This method is the most simple out of the two, but has its limits over the scripting method. The building method will run you through making a trampoline by building a block and changing some properties. On the other side, the scripting side, this method is a lot harder than the building but it has its benefits such as the ability to turn off the trampoline, change the velocity, and even send you propelling forward; We will not be doing such a thing in this tutorial.
- You must have a basic understanding of Roblox Studio
- You must have a basic understanding of what a trampoline is.
- You must have the properties window enabled/visible if you do not have this already (By default it’s enabled/visible). If it’s not visible you enable it by going into View and checking the Properties check.
- If you plan on using the scripting method you must know the basics of the Lua language, and the basics of accessing/changing properties through a script.
- Basic knowledge of the terms used in the tutorial, a list is included below.
Terms You Should Understand
- Velocity - The speed of something in any given direction (In our case, X,Y,Z)
- Lua - Lua is a powerful, fast, lightweight, embeddable scripting language.
The First Step
To begin, we need to create a model that we can use as our trampoline. The components that are essential to this trampoline are very simple. The trampoline needs one single platform that’s anchored, and has
CanCollide set to true so that you don’t fall through it, and that’s all besides the initial requirements. Feel free to make a design, and make it look nice (This will not affect anything pertaining to the functionality of the trampoline).
Fiddling With The Velocity
The way we will make you launch up in the air is with the velocity property in the properties window. This property has 3 values: X,Y,Z. X is the velocity left to right, Y is the velocity up and down, Z is the velocity back and forth. We will be modifying the Y axis so that we can launch them up in the air. The disappointing part of this is that you can only set it so high before the physics act up and make you fall right through the trampoline and baseplate. So the restrictions I will set for you are as follows:
- Do not set the Y Velocity above 200 if you want it to work without your character falling through
- If you are using this once or twice do not set it above 450
If you want to set it higher you can, but there will be undesired effects, such as your character falling through the baseplate on the way back down. In this tutorial we will be using 25-50 as a safe number. So, you’re probably asking when will we make it bounce. We finally will make it bounce, and wrap up the building method. To make it bounce we will want to look in our properties panel (Usually located, by default, under the explorer panel to the right) and find the velocity property.
Next we want to expand the velocity property, like in the picture, and change the Y value to a number of your choice (We chose 25 for this tutorial). Then, believe it or not, you are done and if you step on the block you will be launched into the air! It should also be noted that with this method, the momentum of the character will affect the height of the jump, so if the player never touches the ground, they will go slightly higher with each bounce. Changing the velocity of the X and Z values can also push the player back when they touch them, and as such they can be used to make a one-way door.
The scripting method allows you to do a lot more with the trampoline than its counterpart, the building method. This method allows you to do some pretty neat things, such as randomly adjust the bounce of the trampoline, Adjust the bounce based on a value, allow a user to be launched forward towards a specific point, and many more. Though we will not be covering that stuff in this tutorial, we will be covering the basics of making a trampoline work using Lua. This method is harder than the other because you must know the basics of Lua and how it works with Roblox. I listed a few requirements above that might help you with this section if you want to learn how, I will also direct you to the Cookbook of Roblox’s implementation of Lua.
The First Step
We will need to open a fresh new place and build a trampoline. You can make this very fancy or make it just a basic platform. It doesn’t matter how it looks, it’ll not affect the functionality of the trampoline. Make sure that all the parts are anchored, and that CanCollide is set to true so you do not fall through the trampoline when you try and jump on it.
Now we want to add a Script to the main part of the trampoline, this will be the part that the person will jump on. In this script we will want to delete:
print "Hello world!"
We will now start to make the trampoline work, but we will make it dynamic by using functions. We are using functions so that when you want to change the velocity you can without having to access the the part and changing it manually. Using functions also allows us to use it in a multitude of different ways, and makes it easier to do advanced things later on. The following code is what we will be going with for this tutorial:
function setVelocity(velocity) if velocity == 0 or velocity == nil then -- We check to see if the velocity > 0 and it exists. velocity = 25 -- We set the variable to 25, this is default if you do not include an argument end script.Parent.Velocity = Vector3.new(0,velocity,0) -- We set the velocity of the brick, better than the users torso. end script.Parent.Touched:connect(setVelocity) --The event that will trigger the trampoline, I added this so you can maybe add a check to see if the user is in a group?
This portion of the code states that setVelocity is a function, and will have an argument of velocity that we will use later on.
We then use an if-statement to check if the velocity is set, and that it’s not 0. Is it really a trampoline if you don’t go up in the air?
if velocity == 0 or velocity == nil then
This is setting the argument velocity to 25, I picked 25 because it’s a good medium. By setting velocity we are making it default to 25, and later use it to set the velocity.
velocity = 25
We finally set the velocity of the brick by accessing the bricks Velocity property and changing it with a Vector3 (A number value that represents a 3D space).
script.Parent.Velocity = Vector3.new(0,velocity,0)
This is where it all starts, this is called an event connection line. This will detect when a user hits the block, but it’ll only turn on and not off so you only have to step on it once to turn it on.
Before I finish with the tutorial, I want to make a few notes about the code above. The reason I used an event it because it’s useful when you want to regulate who can pass, and what restrictions apply when you want to use it. I also made the block contain the velocity, and not the player. It’s much more difficult to make the player have the velocity than the block.
This method is simple if you know how, but it’s more useful in the end because, as I said before, it allows you to do much more than using the properties menu.