Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by tony09uk · Jun 11, 2015 at 05:08 AM · vector2bounceplatformsunity4.6

Creating a bounce effect

In essence I am creating a platform game, on the screen are three floors, my character (on the ground floor) should hit an obstacle and bounce back a short distance. However the character is bouncing back a long way and I cannot work out how to resolve it.

This is the script I have created

     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.tag == "Player") 
         {
             GameObject[] charaters = GameObject.FindGameObjectsWithTag("Player");
             foreach(GameObject charater in charaters){
                 //get the CharaterControllerScript
                 CharaterControllerScript controlScript = (CharaterControllerScript)charater.GetComponent(typeof(CharaterControllerScript));
                 //stop all charater movement
                 controlScript.Move = 0;
             }
             GameObject charaterCollision = other.gameObject;
             charaterCollision.rigidbody2D.position = new Vector2(1, charaterCollision.rigidbody2D.position.y);
         }
     }

I believe the problem with this is the last line of the "if" statement. I have tried several different options but the character keeps bouncing back to the beginning of the scene.

I need it to only bounce back a few pixels.

NB: I have tried adding a 2d material to the obstacle, but that bounce the character up to the next floor.

Comment
Add comment · Show 2
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
avatar image abi-kr01 · Jun 11, 2015 at 05:22 AM 0
Share

just a suggestion can't you use physics material and assign .

avatar image tony09uk · Jun 11, 2015 at 09:00 PM 0
Share

abi.kr01. can you please reword that, I don't understand

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by zach-r-d · Jun 11, 2015 at 08:32 AM

I believe you are correct. That '1' in the new Vector2 means that the character will be teleported to x-position 1 whenever the trigger is entered. Try something like this instead:

 charaterCollision.rigidbody2D.position -= new Vector2(1, 0);

This will subtract 1 from whatever x-position the character is currently at.

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
avatar image
0

Answer by saravanan-P · Jun 11, 2015 at 09:14 AM

add a physics2D material to the collider2D in the inspector..

And in that "Physics2D material"..change the Bounciness and friction,

alt text

for example, like this..


pm.png (11.8 kB)
Comment
Add comment · Show 1 · 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
avatar image tony09uk · Jun 11, 2015 at 08:59 PM 0
Share

saravanan P, thank you, I did try that but it did not work for me

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Player Bounces On Ascending Platform After Platform Velocity Is Updated 0 Answers

Does Unity come with a method that finds supplementary angles? 1 Answer

Input System: How to limit a Vector2 input to be only up, down, left or right. 2 Answers

Locking particle axis? 3 Answers

Object should be bouncier 2 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