​ Devlog: Challenges in Creating a Realistic Trampoline Effect for "BouncingCloud" Class


Lately, I’ve been working on implementing a trampoline effect in my class "BouncingCloud" with the intent of providing a satisfying, responsive bounce when a player interacts with the platform. I expected this to be straightforward, but it turned out to be one of the trickier aspects of the project due to the complexities of physics and player interaction. Here’s a breakdown of the key challenges I’ve faced and how I’ve been navigating them.

1. Balancing Physics Control vs. Scripted Control

Initially, I experimented with using a kinematic Rigidbody on the platform to have more direct control over its movements. While this approach worked for scripted motion, it didn’t integrate well with Unity’s physics system when I tried to make the platform respond to the player’s impact. This created issues where the platform didn’t react naturally, making it feel rigid rather than bouncy.

After some trial and error, I switched to a non-kinematic Rigidbody to allow physics-based responses. This helped, but it led to a new challenge—how to precisely control the platform’s behavior while still letting physics handle the realistic motion. It became clear to me that I either needed to rework to algorithm, or implement restraints to prevent the player from being flung so high into the air that Unity could no longer track it

2. Implementing Impact-Responsive Sinking

One of my goals was to have the platform sink when the player steps on it, with the depth and duration of the sink depending on the player’s impact velocity. To achieve this, I had to calculate the player's impact velocity upon landing, and scale the platform's sinking effect accordingly.

The tricky part was finding a balance between the sink depth and the resistance variable that controls how responsive the trampoline should be. I needed the platform to feel responsive enough to give a satisfying bounce but not so soft that it felt unrealistic or inconsistent. Clearly, there were 2 modes of force that needed to be applied, a more gentle, stopping force to "catch" the player, and a stronger force to bounce the player back up. I found great difficulty in striking a balance between the forces in these 2 areas, often either allowing the platform to sink too low, or having the 2nd application of force to essentially act like a brick wall. To me, it was logical to apply force continuously, as that's what would happen in reality, so I used only ForceMode.Force.

3. Gradual Recovery with Opposing Forces

Once I had the sinking mechanic working, the next challenge was ensuring the platform bounced back realistically. My first attempts resulted in the platform bouncing too aggressively, launching the player too high or causing jittery movements. I realized I needed to implement a smooth, gradual opposing force to bring the platform back to its original position after the initial impact.

This led me to develop a system where the platform receives an opposing impulse force on impact to absorb the force, and then over time, a gradual opposing force is applied in the opposite direction to dampen the motion and simulate the elasticity of a trampoline. Tuning the spring frequency and damping to achieve smooth, natural rebounds was a learning curve.

4. Player Interaction and Propulsion

Incorporating player interaction was another layer of complexity. The goal was to use the platform’s rebound velocity to propel the player upward after they land, scaling the force applied to the player based on the platform’s motion and their impact velocity. However, getting this force just right took several iterations. It quickly became clear that applying the exact opposite force would create a reaction that would accumulate and result in the player being launched too far, yet, when scaling the opposite force at lower impact velocities, the platform would barely rebound, or worse, start sinking. I ended up having to include another multiplier that I named propulsion force, which scaled in reverse (ie. lower impact velocities is multiplied by 1 - 1.25, and as the original impact velocity increases, the multiplier starts cutting away at the force with values less than 1).

5. Performance Considerations

As I refined the system, I realized that using Vector3.Distance and similar physics checks in every frame could negatively impact performance, especially as more interactive elements were added to the scene. To address this, I optimized the calculations by using squared distances for basic greater than/less than checks, and limited the more intensive calculations to key moments, such as when the player collides with the platform, when the player leaves the platform and when the platform falls below the sink depth.

Lessons Learned

  • Physics-based interactions are more complicated than they seem, especially when balancing realistic movement with player control. I had to rethink the way I managed forces and velocity to ensure the system felt smooth and intuitive.
  • Performance optimization is crucial when working with frequent physics checks. By reducing unnecessary calculations and using efficient approaches like squared magnitude, I kept things running smoothly.
  • Iteration is key. Tuning the balance between responsiveness and realism in the trampoline effect required several iterations and a lot of tweaking, but it’s led to a much more satisfying result.

As of now, the BouncingCloud trampoline is responsive and realistic, offering the kind of player interaction I envisioned. I’m sure there will be more to refine as the project evolves, but for now, I’m happy with the progress!

Update - Oct 2024: It appears in my built version, this does not function as intended, simply slumping under the weight of the player. More investigation required

Get In Heaven's Shadow

Leave a comment

Log in with itch.io to leave a comment.