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 DevMerlin · Feb 04, 2014 at 12:43 AM · rotationtransformmovement scriptparabola

With power and angle, what is the best way to create a parabolic arc?

I'm creating a custom controller for a Launch-type game. My opening sequence is already scripted and produces two variables: Angle, and Power. I do not want to use this with a Rigidbody and physics but create the actual parabolic arc and movement myself - I'm targeting lower-end devices. What kind of formula, or script would be best for this method?

EDIT: My goal is to do this using transform. I've already set up the smoothing in order to handle the movement.

 transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth);
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 nesis · Feb 04, 2014 at 01:50 AM

I'm not sure if you know this, but if you have a non-kinematic Rigidbody and set its velocity and let gravity influence it, it'll follow a parabolic arc. There are simple, specific equations you can use to calculate a projectile's trajectory.

For a slightly more lightweight solution, could alternatively define a class similar to this (in C#):

 public class MyProjectile : MonoBehaviour {
     public Vector3 gravity = new Vector3(0f,-9.81f,0f); //could instead use Physics.gravity
     private Vector3 velocity;
     
     public void Awake() {
         enabled = false; //start off disabled
     }
     
     public void FixedUpdate() {
         //apply gravity
         velocity += gravity*Time.fixedDeltaTime;
         
         /*if you're wanting to collide with things, here would 
         be a good place to perform physics sweep tests / raycasts
         as needed to know where to stop your object and make it 
         bounce*/
         
         transform.position += velocity*Time.fixedDeltaTime;
     }

     //call this from whatever script / method you want to 
     //initialise a projectile from. Eg, if done in another C# 
     //script, where projectilePrefab is a prefab you've made 
     //with this script attached:
     //GameObject o = (GameObject)Instantiate(projectilePrefab);
     //MyProjectile p = o.GetComponent<MyProjectile>();
     //if (p) {
     //    p.Initialise(somePower,someQuaternionAngle);
     //}
     public void Initialise(float power, Quaternion angle) {
         //here, power is speed (ie the magnitude of velocity)
         velocity = angle * Vector3.forward * power;
         enabled = true; //enable this script's update methods once we've initialised
     }
 }


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

20 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

Related Questions

I'm interpolating an object between positions and rotations. Now I need to make sure it happens in front of the camera. 1 Answer

Transform.rotate limits 3 Answers

GameObject facing fowards 1 Answer

RotateAround Limitations 2 Answers

eulerAngles.y always returns 179.9999 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