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 minimalkid1 · Nov 30, 2014 at 08:42 PM · animationjavascriptsmoothfire1

Animation scripting.

Hello. i work in JavaScripting. I try to animate a knife. I need to change the rotation : x to -50 to cut. But i need to be animated. Smooth move. And before to go rotation x to 0.

 cutstep : int = 0;
 if(Input.GetButtonDown("Fire1"))
 {
 if(cutstep == 0)
 {
 if(SwitchWeapons.Weaponcut == 1)
 {
 cutstep += 1;
 }
 }
 }
 if(cutstep == 1)
 {
 transform.Rotate(Vector3(-50,0,0));
 cutwait();
 }
 if(cutstep == 2)
 {
 transform.Rotate(Vector3(50,0,0));
 cutwait01();
 cutwait02();
 }
 }
 
 function cutwait()
 {
 yield WaitForSeconds(0.01);
 cutstep = 2;
 }
 function cutwait01()
 {
 yield WaitForSeconds(0.01);
 
 }
 
 function cutwait02()
 {
 yield WaitForSeconds(0.01);
 cutstep = 0;
 }

It works but make fast move and look ugly... I can't use animation for this object becouse is a prefab ,and don't work i can't make a new animation, and i try to make a script for animation but is so fast.... Thx.

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 jenci1990 · Nov 30, 2014 at 11:21 PM

 var isAnimate = false;
 
 function Update() {
     if (Input.GetButtonDown("Fire1")) {
         if (!isAnimate) Cut();
     }
 }
 
 
 function Cut() {
     isAnimate = true;
     yield Animate(new Vector3(0,0,0), new Vector3(-50,0,0), 1);
     yield Animate(new Vector3(-50f,0f,0f), new Vector3(0,0,0), 1);
     isAnimate = false;
 }
 
 
 function Animate(_from : Vector3, _to : Vector3, _speed : float) {
     var timer : float = 0;
     while (timer <= 1f) {
         timer += 0.01f * _speed;
         transform.eulerAngles = Vector3.Lerp(_from, _to, timer);
         yield WaitForEndOfFrame();
         //or WaitForSeconds(0.01f);
     }
     transform.eulerAngles = _to;
     return;
 }
Comment
Add comment · Show 4 · 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 minimalkid1 · Dec 01, 2014 at 12:02 AM 0
Share

if i press 1 click i cut with knife in front but when i change the position of my character the knife cut in other direction... The knife is attached to $$anonymous$$ain Camera... And if i rotate the camera i cut in back...

avatar image jenci1990 · Dec 01, 2014 at 12:09 AM 0
Share

In Cut function change the last parameters:

 yield Animate(new Vector3(0,0,0), new Vector3(-50,0,0), 1);
 yield Animate(new Vector3(-50f,0f,0f), new Vector3(0,0,0), 1);


like this: (2x faster)

 yield Animate(new Vector3(0,0,0), new Vector3(-50,0,0), 2);
 yield Animate(new Vector3(-50f,0f,0f), new Vector3(0,0,0), 2);

avatar image minimalkid1 · Dec 01, 2014 at 12:11 AM 0
Share

if i press 1 click i cut with knife in front but when i change the position of my character the knife cut in other direction... The knife is attached to $$anonymous$$ain Camera... And if i rotate the camera i cut in back... Please help... I try a lot of posibilities but nothing...

avatar image jenci1990 · Dec 01, 2014 at 12:13 AM 0
Share

replace transform.eulerAngles to transform.localEulerAngles

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Activating an Animation? 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Rotating An Object On Its Axis Once 3 Answers

How to use/apply multiple animations correctly? 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