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 Morcovman · Jun 11, 2019 at 06:49 AM · velocityaddforcetrajectoryarcballistic

Moving the player in a ballistic trajectory in 3D

Hi! I'm currently struggling with this issue for about two weeks and can't seem to get the hang of it.

Here's the premise: I want to create a 3D platformer where one of the player's abilities is to "slingshot" around the levels. Think Angry Birds, but in 3D.

I've currently managed to get a system working where the player can visualize the trajectory arc and control its velocity (a float) and angle (). What I want to do next is: after a certain button is pressed, the game takes the velocity and angle provided and moves the player object along that trajectory.

The problem I'm having is that the player object either doesn't move at all, or is thrown into the distance at great speed. I've tried both the rigidbody.AddForce method and modifying the player's rigidbody velocity directly.

I originally figured that if I calculate the velocity vector and use that as the force, it would work, but it didn't.

From my projectile arc generator, I can get the angle, velocity (float) and target position of the trajectory.

Here's the code for the trajectory movement & velocity: Note: the Slingshot1 function is simply called in Update (for testing purposes).

     private void Slingshot1()
     {
         if (inputJump)
         {
             slingVelocity = CalculateAngularVelocity(transform.position, aMesh.GetTargetPosition(), aMesh.GetAngle());
             rb.AddForce(slingVelocity, ForceMode.VelocityChange);
             //StartCoroutine(SlingshotTimer());
         }
     }

 private Vector3 CalculateAngularVelocity(Vector3 start, Vector3 target, float angle)
     {
         Vector3 direction = target - start;
         float h = direction.y;
         direction.y = 0.0f;
 
         float distance = direction.magnitude;
 
         float a = angle * Mathf.Deg2Rad;
 
         direction.y = distance * Mathf.Tan(a);
         distance += h / Mathf.Tan(a);
 
         //Velocity calc
         float velocity = Mathf.Sqrt(distance * Physics.gravity.magnitude / Mathf.Sin(2 * a));
         return velocity * direction.normalized;
     }

Thank you for taking some time for looking into this issue!

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

0 Replies

· Add your reply
  • Sort: 

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

108 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

Related Questions

Calculate Velocity of Impulse 0 Answers

rocketscience - how to find out what force is needed to hit a specific target 2 Answers

Why is velocity checking intensive? 0 Answers

Moving a camera with AddFoce, or setting velocity, need help 1 Answer

How to use AddForce and Velocity together 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