Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 hsnzkg · May 03, 2021 at 02:50 PM · c#programminguser interfaceworldspacemechanics

Throw 3D object parabolically -> From 2D Canvas to WorldSpace

I created 2 cameras 1 for the 3D object rendering for UI and other one basicly rendering the whole scene.

My question is how can I create object and throw parabolically from UI 3D object position to world space position ? alt text

1.png (21.4 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
0

Answer by Koyemsi · May 03, 2021 at 04:07 PM

Hi.

Here is how I think I would proceed.

First thing would be to instantiate the 3D cube you want to throw, considering the one shown in the UI is only a rendering texture.

You will calculate its initial 3D position (and maybe also its scale and rotation) in order to give the impression that it’s thrown from the UI.

For the position, use Camera.ScreenToWorldPoint(), like this :

Camera cam; // this is your 3D cam
GameObject UIcube; // this is your UI element showing the cube
GameObject prefabCube; // no comment
float x = UIcube.transform.position.x; float y = UIcube.transform.position.y; float z = -cam.transform.position.z; Vector3 initPoint = cam.ScreenToWorldPoint(new Vector3(x, y, z));
GameObject cube = Instantiate (prefabCube, initPoint, someRotation);


For the motion, it depends.

I hope you don’t want it based on physics because you would have to apply a very finely tuned force ; seems nearly impossible. I would use an interpolation system like iTween.

For the parabolic motion, you could define a path using 3 points : the start point (initPoint), the target point and an intermediary one ; this one would be positioned between the start and target points, but with some x offset so that the path becomes a curve.

An example :

Vector3 initPoint; // the one we just defined 
Vector3 targetPoint; // the end of the road ;)
Vector3 interPoint = targetPoint - initPoint;
interPoint.x += Random.Range(1f, 3f); // give a random offset for curvature
Vector3 [ ] path = new Vector3 [ ] {initPoint, interPoint, targetPoint};

// finally, do the motion : iTween.MoveTo(cube, iTween.Hash( "path", path, "time", 2f, "easetype", iTween.EaseType.easeInOutQuad ));

I didn’t try this code, so I hope it will work and be of some help ;)
Comment
Add comment · Show 3 · 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 hsnzkg · May 03, 2021 at 04:46 PM 0
Share

I will try your concept as soon as possible and make a comeback about it.

Thank you so much in advance :)

avatar image Koyemsi hsnzkg · May 03, 2021 at 04:55 PM 0
Share

My pleasure. Good luck !

avatar image Koyemsi hsnzkg · May 03, 2021 at 05:05 PM 0
Share

Forgot to say that you probably will have to also tween the rotation in the same time as you move the cube, so that it imbricates perfectly with the other cubes. Use iTween.RotateTo() with the same duration.

Hint : to see all of the available iTween parameters, right-click on the "RotateTo" then choose "Reach declaration" (Ctrl+D) ; this will display the method in iTween.cs with all params.

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

119 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

Related Questions

Multiple Cars not working 1 Answer

RawImage - Cannot update material's UV offset. 1 Answer

Distribute terrain in zones 3 Answers

What exactly is going on when I implement Update(), and other messages in MonoBehaviour 2 Answers

Yet Another Bullet Decal Problem 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