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 8bit4life · Aug 19, 2015 at 11:51 AM · animationmovementeditorcurvefield

How can I define two-dimensional curves? (like: circle)

Hi fellow Unity devs,

I'm looking for a way to define two-dimensional enemy movement in my game and I really like the animation curve fields. However, it'd be extremely hard for me to define all sorts of nice loops different kinds of enemies could move along using two separate curve editors. Is there a way I could define curves on two (X/Y) dimensions in one single editor? The simplest example is a circle. That's a separate SIN and a COS on X/Y respectively.

Thank you.

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 _dns_ · Aug 19, 2015 at 02:58 PM 1
Share

Hi, using splines could be a solution, check the asset store. It's also not so difficult to implement as a game and editor extension.

avatar image 8bit4life · Aug 19, 2015 at 03:39 PM 0
Share

Thanks dns. I'm looking at this tutorial: http://www.habrador.com/labs/catmull-rom-splines/ I was looking for a built-in field type that the inspector would recognize, but if there's no better option, I'll think about adopting the approach seen in the tutorial.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cjdev · Aug 19, 2015 at 07:43 PM

For my own uses I found Bezier curves to be the easiest to work with. Quadratic Bezier curves are the simplest as they use only one control point. Basically how they work is you pick a starting and end point and a control point which determines the direction the curve bends out towards. See this picture for an example:

alt text

You input the three points, v0 (starting point), v1 (control point), and v2 (ending point), as well as a time t between 0 - 1 which determines where along the curve you are as a percentage. The equation and code implementation for this is actually very easy and you can see a function here that returns a point on the curve at time t give your three points:

 public Vector2 CalcBezier(Vector2 p0, Vector2 p1, Vector2 p2, float t)
 {
     return new Vector2((1 - t) * (1 - t) * p0.x + 2 * (1 - t) * t * p1.x + t * t * p2.x,
                         (1 - t) * (1 - t) * p0.y + 2 * (1 - t) * t * p1.y + t * t * p2.y);
 }



bezier.png (9.7 kB)
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 8bit4life · Aug 20, 2015 at 10:52 AM 0
Share

Thanks djdev, this is great advice. I think it'd be workable for my needs. The only thing is that I'll still need to create an editor solution for this (either a custom inspector or a game object based one as shown in the tutorial I linked), but this seems inevitable, so there's no point keeping this question open. Accepted.

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

27 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

Related Questions

Animator Editor adding unwanted curves 0 Answers

Deleting animation curve with editor script 1 Answer

Animation not working correctly on moving object 1 Answer

made a ring collider from sphere colliders and a bar collider, but when animated the ring doesn't stay on bar 0 Answers

Is there a way to display the animation curve during the runtime like in the editor? 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