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 Jotakuun · Jun 25, 2015 at 10:29 AM · rendererprojectilecurvebezier

Draw a bezier curve and shoot a projectile in same direction

Hello!

I'm actually trying to make a similar control like Angry Bird. I want to make a bezier's curve renderer in real time acording to input touch. And when input ends I want to shoot an arrow exactly in the same direction. Which it's best way to make this? I've already have this mechanism almost working with a Line Renderer and Vector3.Lerp but I want to change it to a curve.

alt text

Comment
Add comment · Show 2
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 hexagonius · Jun 25, 2015 at 10:39 AM 0
Share

How about the opposite. Ins$$anonymous$$d of making your projectile follow a curve, calculate the curve based on the physics values used for the object. That would make it easier on impact, cause everything is already physically setup.

avatar image Jotakuun · Jun 25, 2015 at 10:44 AM 0
Share

How can I calculate that? I'm intermediate skilled in C# but I don't know anything about advanced maths. What should I do?

2 Replies

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

Answer by Piflik · Jun 25, 2015 at 11:00 AM

This code gives you a point on a bezier curve, given the 4 control points and a value between 0 and 1 (0 being the start of the curve, 1 the end).

 public class Bezier {
     public static Vector2 interpolate(Vector2 start, Vector2 end, Vector2 A, Vector2 B, float f) {
         Vector2 a = Vector2.Lerp(start, A, f);
         Vector2 b = Vector2.Lerp(A, B, f);
         Vector2 c = Vector2.Lerp(B, end, f);
     
         Vector2 d = Vector2.Lerp(a, b, f);
         Vector2 e = Vector2.Lerp(b, c, f);
     
         return Vector2.Lerp(d, e, f);
     }
 }


But for this, a bezier curve is not really applicable, since you only have two control points (the start position and a vector based of the start velocity). For this I would use a basic euler integration:

 Vector2 startPos, startVel;              //these would be set via your touch input
 Vector2 gravity = new Vector2(0, -1);    //change as needed
 int steps = 10;                          //how many points
 float distance = 10;                     //how far
 
 Vector2[] curvePoints = new Vector2[steps];
 
 curvePoints[0] = startPos;
 Vector2 tmpVel = startVel;

 float h = distance/steps;
 
 for (int i = 1; i < steps; ++i) {
     curvePoints[i] = curvePoints[i-1] + h * tmpVel;
     tmpVel += h * gravity;
 }

The curvePoints array now holds the points that can be drawn either via a LineRenderer or any other way of visualisation.

Comment
Add comment · Show 2 · 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 Bunny83 · Jun 25, 2015 at 11:28 AM 1
Share

+1
For some reason i can't find the question to this example i've made (After 20 different specialized google searches i've given up...^^)

There's a unitypackage link at the bottom.

(I really should add the question link to those builds ^^)

avatar image Jotakuun · Jun 25, 2015 at 07:14 PM 0
Share

I've finally make my script working with this, thank you guys :)

avatar image
0

Answer by CasperK · Jun 25, 2015 at 12:39 PM

I Like to use a method like this, having it possible to poll on any part of the curve. Its based on y = gt^2/2 + vit.

     float gravity=-.91f;
     Vector2 PolCurve(Vector2 position,Vector2 speed,float time)
     { 
         return (new Vector2(position.x + speed.x*time,position.y + gravity * (Mathf.Pow(time,2f))/2f + speed.y * time));
     }

That way you can also have them moving along the line like some games have by using an offset on the time.

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 Jotakuun · Jun 25, 2015 at 07:17 PM 0
Share

This could works too but I didn't test it, thank you anyway :)

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

24 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

Related Questions

Bezier curver using LineRenderer 0 Answers

Please help, bullet drop is wrong at certain angles ? 0 Answers

Controlling the curvature of a Bézier curve 2 Answers

Which Variables control the shape of a Beizer Curve? 1 Answer

iTween, HOTween, Spline Controller and Others 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