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 Codelyy · Jan 03, 2017 at 06:18 AM · c#movementvelocityanimationcurve

Using Animation Curve for Movement Help

I'm trying to recreate the sonic boss fight from the game "I wanna be the Boshy" just for fun and for learning purposes, currently I'm recreating this attack: https://youtu.be/h_o8AnZX9FA?t=19s

Currently I've scripted the boss fight like this:

 public void SuperFly(float speed, float maxSpeed)
     {
          float xa = speed;
          float ya = speed;        
  
          flyV.x = Mathf.Clamp(flyV.x, -maxSpeed, maxSpeed);
          flyV.y = Mathf.Clamp(flyV.y, -maxSpeed, maxSpeed);
          rig.velocity = flyV;
  
          Vector2 v = rig.velocity;
          float angle = Mathf.Atan2(v.y, v.x) * Mathf.Rad2Deg;
          transform.rotation = Quaternion.AngleAxis(angle, transform.forward);
 
          if(!runningState) //Start Of State
          {
              stateTimer = 30f;
              anim.SetTrigger("SuperFly");
              transform.position = transformPoint.transform.position;
              ChangeDirection("Right");
              flyV = rig.velocity;
              runningState = true;
          }
  
          if (transform.position.x > player.transform.position.x)
          {
              flyV.x -= xa;
          }
          else
          {
             flyV.x += xa;
          }
  
          if (transform.position.y > player.transform.position.y)
          {
             flyV.y -= ya;
          }
          else
          {
             flyV.y += ya;
          }
     }


and it gives sort of similar movement to the movement in the actual game: http://i.imgur.com/ctjL3lF.gif (Not a good recreation, still got a lot to do). If you compare the movement of sonic from my version to the actual game version then you can notice there something different about it, sonic's movement in the actual game seems for quick and sharp compared to my version, I actually created a topic a couple of days ago asking about this and someone gave me this: https://s-media-cache-ak0.pinimg.com/originals/6c/1b/a4/6c1ba40bf194cd0fc99c06207246b51f.gif

The thing is I'm just not sure how I can implement that into my script and I was wondering if someone would help me?

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 UnityCoach · Jan 03, 2017 at 10:51 AM

You can use Animation Curves. Simply expose a parameter of type AnimationCurve, set it up in the Editor, then in the code, use curve.Evaluate (position) to get the value at the given position. In these cases, I always make my curves go between 0 and 1 on both time and value, then I usually use the result in a Lerp if I want it to go beyond that.

like :

 result = Mathf.Lerp (min, max, curve.Evaluate (position));
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 Codelyy · Jan 03, 2017 at 05:51 PM 0
Share

I've set up an animation curve though I'm just not sure how to implement

 result = $$anonymous$$athf.Lerp ($$anonymous$$, max, curve.Evaluate (position));

into my script and have it, of course work correctly.

Would I use that statement for both the X and Y axis of sonic? Since what I'm doing in my current script is adding onto sonic's x and y velocity by 0.5 depending on the position of the player.

avatar image UnityCoach Codelyy · Jan 03, 2017 at 06:37 PM 0
Share

Yes, I believe, you need two curves, or maybe just one if you want the same behaviour on X and Y.

avatar image Codelyy UnityCoach · Jan 03, 2017 at 06:46 PM 0
Share

I was going to use one curve for both the x and y axis though I'm not sure if that's best to get the same movement sonic has in the actual game.

I'm still unsure how to implement that into my script though, I've done it like this but that clearly wrong as it doesn't work XD:

  if (transform.position.x > player.transform.position.x)
          {
              //flyV.x -= xa;
              flyV.x = $$anonymous$$athf.Lerp(-maxSpeed, maxSpeed, flyCurve.Evaluate(transform.position.x));
          }
          else
          {
             //flyV.x += xa;
             flyV.x = $$anonymous$$athf.Lerp(-maxSpeed, maxSpeed, flyCurve.Evaluate(transform.position.x));
          }
  
          if (transform.position.y > player.transform.position.y)
          {
             //flyV.y -= ya;
             flyV.y = $$anonymous$$athf.Lerp(-maxSpeed, maxSpeed, flyCurve.Evaluate(transform.position.y));
          }
          else
          {
             //flyV.y += ya;
             flyV.y = $$anonymous$$athf.Lerp(-maxSpeed, maxSpeed, flyCurve.Evaluate(transform.position.y));
          }

The flyV variable is sonic's velocity and the maxSpeed variable is the max speed sonic can reach in both directions.

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

269 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 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 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

Making a bubble level (not a game but work tool) 1 Answer

Super Sonic Movement Help 1 Answer

Return Proper Velocity of Player object 3 Answers

Prevent Object/Character from "drifting" away from Collider 1 Answer

Bullet not moving from script 3 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