Creating a Trampoline type object?
I've been thinking about how to script a trampoline type object.
I'm just trying to work on my coding by scripting 2D elements and the first one I want to try is a trampoline type object.
For simplicity sake lets just say the player falls or jumps onto the object, the object then sends the player X distance in the air.
I did some messing around and the effect I got looks more like teleporting, it wasn't smooth. I wouldn't say I was going in the right direction, I am rather new at this.
What would be a good way to do this?
Answer by OncaLupe · Dec 17, 2015 at 07:14 AM
Like most things in Unity, and programming in general, there's many ways to do things. It depends on how you have your movement system working.
If you're using a physics based movement, then the trampoline can probably just use the player's rigidbody AddForce() to push them upwards and let the physics system do the work. However if you're manually moving to positions, you may have to send a command to the player movement script, and have it move the player upward, similar to however you trigger a jump.
If you can show your movement code (provided you've gotten that far as you mentioned you're just starting), then we can possibly provide some more specific info.
If you want to see the entirety of my Player file here it is: https://dl.dropboxusercontent.com/u/3801241/Code/Player.cs
I went through like a 9 part tutorial doing basic stuff like movement, jumping, wall jumping, camera following, physics, and moving platforms.
Since it was my first time in Unity and writing C# (I came from Java so it was pretty easy) then I don't fully understand what I did in the tutorial nor do I have a good grasp on the Unity API or thinking clearly how to go from A to B when trying to code something.
But there is the Player file, the tutorial didn't use rigidbody, it used BoxColliders and Raycasting so I'm not sure if AddForce() can be applied here.
Your answer
![](https://koobas.hobune.stream/wayback/20220612052933im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity Player bumps when falls and dash 0 Answers
how to clamp( set max value) the velocity of a 2d rigidbody? 1 Answer
Choosing speed and direction of AddForce 1 Answer
Change the "jumping speed" in the FirstPersonController by using another script 0 Answers
Moving player left and right (HELP) 1 Answer