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 braco86 · Oct 07, 2014 at 12:10 PM · inheritancefunction call

Trying to use a derived Function with C#

Hi, it's all about my BounceBack() Function! In my Teammate Class, my Teammate ist bouncing the Ball back pefectly with a Lerp. But when i call this Function out of my Wall Class, the Ball is not bouncing back from the Wall, its kinda shaking in a weird way.

Some Informations: The static Variables are needed, because every class is calculating with one unique Position. ballCollision is not static, because every Class has it's own Instance of the Variable. The passWay Variable is calculated once when the Ball hits a Teammate or the Wall.

I don't know what to do, i've tried a lot of things like writing a own Function with the same content but still the same! i Think there is a Problem with the passWay or ballPos.. This ist my first game and my first Question here =) I Hope someone can help me. Greetings from Germany

Here's the Code with just the important Functions/Variables

 public class ball : MonoBehaviour {
     
     protected static Vector3 ballPos;
     protected static Vector3 passWay;
     protected bool ballCollision;
 
     void Update () {
             ballPos = transform.position;
         }
     }
 
     void OnCollisionEnter(Collision collision) {
         if (collision.gameObject.tag == "Teammate" || collision.gameObject.tag == "Wall") {
             passWay = new Vector3 (player.playerPos.x, 0, player.playerPos.z + 4);        
         }
     }
 }


     public class player : ball {
 
     public static bool ballHave
     public static bool passRight;
     public static bool passLeft;
   }


 public class teammate : player {
 
     void Update () {
 
             BounceBack ();
     }
 
     public void BounceBack () {
         
         if (ballCollision && !player.ballHave) {
             Ball.transform.position = Vector3.Lerp (ballPos, passWay, Time.deltaTime *3);
             passRight = false;
             passLeft = false;
             
         }    
     }


 public class wall : teammate {
     
     void Update () {
             
         BounceBack ();
     }
 
     void OnCollisionEnter (Collision collision) {
         
         if (collision.gameObject.tag == "Ball") {
             ballCollision = true;
         }
     }
 }













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
0

Answer by Spinnernicholas · Oct 07, 2014 at 05:23 PM

You are using Lerp the wrong way.

All Lerp does is take a percentage and return a fixed vector. Giving it 0 returns the start. 1 returns the end. .5 returns half way between the beginning and the end.

So,

  • You will have to determine how long the bounce will take.

  • Accumulate the time that has elapsed since the bounce started.

  • And finally, divide that by the total bounce time and pass it to lerp.

I don't have time to find an example at the moment, but if you are still having trouble later, I will try and help more. There may be an answer on this site on how to use lerp, try searching for it.

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

An OS design issue: File types associated with their appropriate programs 1 Answer

Access local method variable in derived class 2 Answers

Inheritance structure 0 Answers

How to pass parameters to function that is stored in variable? 1 Answer

function that returns multiple variables (in this case, lists) 1 Answer


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