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 Ssiroo · Jul 17, 2014 at 02:01 AM · javascript3dsway

Animator canceling a script (sway)

Hello, I create a sway script for my flashlight and attached it to the gameobject(flashlight).

Now the problem is that when I enable the animator in the gameobject(flashlight) the sway doesnt work,but when I disable it,it does work. This is the script :

 #pragma strict
 
 var flashLight : Transform;
 var xSwayAmount : float = 0.1;
 var ySwayAmount : float = 0.05;
 var maxXAmount : float = 0.35;
 var maxYAmount : float = 0.2;
 private var vector3 : Vector3;
 var smooth : float = 3.0;
 
 function Start () {
     vector3 = flashLight.localPosition;
 }
 
 function Update () {
     var fx : float = -Input.GetAxis("Mouse X") * xSwayAmount;
     var fy : float = -Input.GetAxis("Mouse Y") * ySwayAmount;
     
     if(fx > maxXAmount)
     fx = maxXAmount;
     
     if(fx< -maxXAmount)
     fx = maxXAmount;
     
     if(fy > maxYAmount)
     fy = maxYAmount;
     
     if(fy < -maxYAmount)
     fy = -maxYAmount;
     
     var detection : Vector3 = new Vector3(vector3.x + fx, vector3.y + fy, vector3.z);
     flashLight.localPosition = Vector3.Lerp(flashLight.localPosition, detection, Time.deltaTime * smooth);
 }


Has anyone got any idea why is this happening ? I need the animator to play my animations so I can't just disable it.Thank you.

Comment
Add comment · Show 1
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 Ssiroo · Jul 17, 2014 at 06:12 PM 0
Share

Bumpppp...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by yagizpoyraz · Jul 17, 2014 at 07:49 AM

Create an empty gameobject (will be called parent) which holds your current gameobject. Move your animator to your parent object, sway can stay on your gameobject.

This should work.

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 lukaodzelashvili · Oct 17, 2020 at 12:39 PM 0
Share

THANK YOU!!!!!!!!!!!!!!! AND WHY DOES IT HAS -1 VOTES WTF IT WORKED THANKS $$anonymous$$AN!

avatar image
0

Answer by smallbit · Jul 17, 2014 at 02:44 AM

(just a guess) It might be because your animation overrides the sway?. You said you have sway script and animator in the same GameObject, try to create another GameObject, attach sway script to it, and make your current GameObject(flashlight) with animator as a child of that GameObject (reset Transform).Let me know how it works for you.

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 Ssiroo · Jul 17, 2014 at 12:37 PM 0
Share

I tried that before,it did not work.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get a smoother slow motion 0 Answers

Projectile movement in 3D 1 Answer

Inspector Problems or possible miss script. 0 Answers

Load Large Size Model Unity3d 2 Answers

How to make a mesh adjust its form around specific points 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