Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed May 03, 2017 at 12:01 PM by Ty1eRRR for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ty1eRRR · Apr 20, 2017 at 09:01 AM · movement2d gamecircletrajectory

After colliding move the object back by the same circle trajectory

Hi, guys. I am stuck with one feature and I have no idea how I can make it further. Would be much appreciated for the help or a hint. So the point is, when the green ball(see attached screenshot) will collide with the racket, I want the ball to move backward(by the same trajectory). The ball and the racket have both defined Circle Colliders 2D.

Here is the code for my ball logic:

  public class BallMovement : MonoBehaviour {
     
         private float RotateSpeed=1.3f;
             private float Radius = 1.4f;
     
             private Vector2 _centre;
             private float _angle;
             private Vector2 offset;
     
         void Start()
         {
             _centre = transform.position;
         }
     
         void Update()
         {
           
             _angle += Time.deltaTime * RotateSpeed;
     
     offset = new Vector2 (-Mathf.Cos (_angle), Mathf.Sin (_angle)) * Radius;
     
             transform.position = _centre + offset;
     
             RotateSpeed+=acceleration;
             if(RotateSpeed>maxSpeed){
                 RotateSpeed=maxSpeed;
         }
     
         void OnTriggerEnter2D(Collider2D other) {
             if (other.gameObject.CompareTag("Racket")) {
 
 // I thought I could make it in this way, but it is not working. And I think it is not the best approach at all            
     offset = new Vector2 (-Mathf.Cos (_angle), -Mathf.Sin (_angle)) * Radius;
             } 
         }
     }

   

I attach here the screeshot for better visual understanding. alt text

Thanks.

screen-shot-2017-04-18-at-192622.png (61.3 kB)
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

  • Sort: 
avatar image
1
Best Answer

Answer by alph1 · Apr 28, 2017 at 08:53 AM

You should remove - of your mathf.cos and sin.You should substract a value from your angle not make it negative.if you move with +1 angular speed in the first place and when you need to move reverse as you described you should move with -1 angular speed to change movement direction, so you should use this line of code new Vector2(Mathf.Cos(_angle-YOURangularspeed,Mathf.Sin(_angle-YOURangularspeed))).

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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Moving in circles 1 Answer

How to move along a few path follow ? 1 Answer

Move 2D Sprite Horizontally With Mouse 1 Answer

Move player in circle around center 0 Answers

My Player doesn't move anymore. I didn't change a thing in the script and it did work before. What's wrong? 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