• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Okido · Jan 07, 2017 at 07:38 PM · physicsbounce

Creating a bouncy surface, where player is propelled with the same force as it hits

Hi,

I'm trying to create bouncy surfaces, where the player will be propelled to the same height from which it fell on collision. The same way the blue gel works in Portal 2, if I remember rightly!

(so, if the player jumps from a 3m high platform onto a bounce surface, they will be bounced back up to that height, and if they jump onto the same surface from 10m, they'll be launched 10m back up into the air, and so on)

The Bounce physics material does exactly this, but the material has to be applied to the falling object it seems, which makes it bounce off of everything. I don't want the player character to be bouncy, just bounce when hitting particular surfaces. Is there a way to attach the bounce material to the floor, rather than the object, and get the same behaviour? Or will it need a script?

Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Osakajin · Jan 07, 2017 at 08:01 PM

You should be able to apply the physic material to whatever you want. In my experience, it helps to have a material with a Bounce value for everything, though, i.e. your player should have a bouncy physic material with a low bounce setting (unless your player is made of flubber) and the object should have its own material with a high bounce setting.

When I tried this, it didn't give enough bounce. For that project, though, my player objects were moving fast enough that I had a bullet-through-paper problem and my player could fly through the walls of the arena. My solution was to apply a physics force to the player rigid body at a certain distance from the wall's origin (it was a big sphere, which helped the math).

 using UnityEngine;
 using System.Collections;
 
 public class Boundary : MonoBehaviour {
 /// <summary>
 /// This script causes a soft bounce effect on approaching the wall. This prevents the bullet-through-paper issue that we were having while relying strictly on the collider of the sphere to contain player movements. 
 /// The distance at which the effect is triggered is significantly smaller than the sphere's actual radius; this was due to smaller, faster ships being able to gain enough velocity to push all the way through the
 ///  sphere's mesh before the physics engine added enough backwards force to push them back inside. 
 /// </summary>
 
     private Rigidbody rb;
 
     void Awake () {
         this.rb = GetComponent<Rigidbody>();
     }
 
     void Update () {
         Vector3 directionToOrigin = this.transform.position;
         if (directionToOrigin.sqrMagnitude > 249980) {
             this.rb.AddRelativeForce(this.transform.InverseTransformDirection(-this.transform.position)*10);
             //the scalar at the end of the above line will influence both how slowly a ship can be going and still touch the sphere collider, as well as how much of a push towards the middle they will get.
         }
     }        
 }

The effect was the player ship would suddenly slow down, barely kiss the wall, then get propelled backwards at about the same speed it was moving forwards. It worked for glancing blows, direct strikes, backwards... It might be overkill if your player isn't moving 50 m/s, but it makes for a very nice bounce.

And full disclosure, this project was over a year ago, it was my first non-tutorial project, and I've been on hiatus since shortly after writing this solution. There may be tricks to physic materials I don't know.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

121 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody wont bounce off other rigidbody, why? 1 Answer

Bounciness of 1 sticking to walls 1 Answer

Ball Bounce And Rotating Walls 0 Answers

Objects wont stop bouncing if they fall. 0 Answers

How do I get an object to behave like a balloon? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges