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 /
avatar image
0
Question by Profed · Jan 05, 2017 at 06:10 PM · rotationphysicsquaterniondirection

How to apply parent based rotation?

Hello everyone. So, i'm learning to code by re-making popular games on my own. Currently i'm working on an AngryBirds clone and i got a problem with blue bird mechanics.

FAQ: The bluebird (big bird) in angry birds is thrown like a regular bird, but when you tap on a screen again, it is devided into 3 smaller birds, all of which continue to move at a direction based on a direction a bigger bird had before separation.

alt text

That doesn't matter whether the big bird fly to the right of the screen or straight downwards or else, it always seem to separate in 3 birds, of which the middle one following the same direction, and with the corner birds going like ~ +15 and ~ -15 degree from the original direction.

Problem: Unfortunately i have no idea, how to "get" the rotation, from the direction it was moving, to add +15 and -15 degrees to corner birds. Currently, to spawn them i use:

 Instantiate(smallBird, position, Quaternion.Euler(0, 0, 15));
 Instantiate(smallBird, position, Quaternion.Euler(0, 0, 0));
 Instantiate(smallBird, position, Quaternion.Euler(0, 0, -15));

That is totally wrong, as you understand, because it always spawn them facing the same angles. I believe there is a way to somehow put all the direction information together to initially spawn them rotated at right angles on Z axis. Then, using "Vector3.right" to apply force to move them "forward" (X axis).

alt text

Important: I'm using 3D physics with Z axis position and X,Y axis rotation freezed.

After the big bird is launched it doesn't rotate at all until it hit something, so i guess i can only get rotation using direction it was moving. (Somehow).

Or maybe if there is a way i can make big bird turn to the direction it is flying on it's X axis, it could solve the problem, too.

Here is a piece of launch code i use, for that case:

 startPosition = birdBody.transform.position;
 
 void OnMouseDrag()
     {
         if (active == true && thrown == false)
         {
             mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 15));// 15 потому что камера по Z в -10.
             Vector3 originClampPoint = mousePosition - startPosition;
             transform.position = Vector3.SmoothDamp(startPosition + Vector3.ClampMagnitude(originClampPoint, dragRange), mousePosition, ref velocity, smoothDrag, maxSpeed);
         }
     }
 
 void OnMouseUp()
     { //something not important//
 birdBody.AddForce((startPosition - dragPosition) * throwPower, ForceMode.VelocityChange);
 }

And again, after the launch it doesn't rotate at all.

Hopefully either of solutions is achievable, i would be glad to hear any working anyway. Thx in advance, and sorry for bad English.

3302918bc3fe4494832ff9804bca7dc2.png (23.6 kB)
15c55a8ccb4c4fc582eae384879d67f1.png (41.8 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

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

Answer by KoenigX3 · Jan 05, 2017 at 07:45 PM

As i can remember, in the original AngryBirds the parent bird does not rotate, it stays at the identical rotation. However, i can give you a solution.

If you want to rotate the parent bird into the direction of movement, you can use this:

 transform.LookAt(transform.LookAt(transform.position + birdBody.velocity);

From now, you can use the rotation of the parent bird to spawn the children:

  Instantiate(smallBird, position, Quaternion.Euler(transform.rotation.EulerAngles + new Vector3(0, 0, 15)));
  Instantiate(smallBird, position, transform.rotation);
  Instantiate(smallBird, position, Quaternion.Euler(transform.rotation.EulerAngles - new Vector3(0, 0, 15)));

Maybe you need to switch the operators on the first and the third child (i don't know which one faces up or down).

(Note: If the script is not on the parent bird, you should change transform.position and transform.rotation to the parent bird's transform.position and transform.rotation in every case)

I hope that this will help you in solving the problem.

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 Profed · Jan 06, 2017 at 10:25 AM 1
Share

Worked for me, but i had to change

 Instantiate(smallBird, position, Quaternion.Euler(transform.rotation.EulerAngles + new Vector3(0, 0, 15)));

for

 Instantiate(smallBird, position, Quaternion.Euler(transform.rotation.EulerAngles + new Vector3(15, 0, 0)));

Adding angle to Z axis messed everything, because "LookAt" function makes it fly with Z axis "forward" not with X axis:

alt text

Also you doublewrite transform.LookAt. Well, at least for me that worked only in this form:

 transform.LookAt(transform.position + birdBody.velocity);

Yeah, as i've said in original AngryBird they doesn't rotate while in flight, but this is nice solution as to me. Thank you!

74b7728e3e5746629efe86f6f011862a.png (21.0 kB)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotate vector3 relative to another vector3 1 Answer

Copy Rotation Direction only on Y Axis. 1 Answer

Rigidbody wont rotate in the other direction. 0 Answers

Rotation direction in coroutine 2 Answers

Constant 3D rotation (torque, angular acceleration, etc) GLOBAL to object in space? 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