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 paulknight10 · Jan 19, 2015 at 11:38 AM · animationphysicsraycastcolliderfbx

Can you gradually slow an fbx animation on raycast hit, then speed it up again after a certain amount of time?

Hi all,

Not sure how well i have explained this, but hopefully someone out there will understand what i want to do..

I have a series of path animations baked into an fbx file that i would like to gradually slow down using a raycast that shoots a ray forward, checks the tag on the gameobject then slows the animation state speed if the tag on the gameobject is marked "pod". I have some javascript working for this so far, but i would like it to gradually slow the animation whereas at the moment it slows it instantly. Once it has slowed for a period of time, lets say 5 seconds, i would then like it to speed up again until the next raycast hit is called.

This is the code i have so far:

 #pragma strict
 
 function Update () {
     var hit : RaycastHit;
     if (Physics.Raycast(transform.position, transform.forward, hit, 10.0 ))
         {
             if(hit.collider.tag == "Pods")
             {
                 for (var state : AnimationState in GetComponent.<Animation>())
                 state.speed = 0.05;
                 print (hit.collider.tag);
                 Debug.DrawLine (transform.position, hit.collider.transform.position,Color.red);
             }
         }
 }

Also i have noticed that the frame rate drops dramatically when there are a lot of raycast hits. I think this casts a ray every frame? Should/could i cast the ray in a different way to get less of an impact on frame rate? Or am i tackling this in completely the wrong way?

Any help would be hugely appreciated!

Many thanks,

Paul

Comment
Add comment · Show 4
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 paulknight10 · Jan 19, 2015 at 11:05 AM 0
Share

Removing the print and debug has drastically improved the frame rate, so thanks for that idea. If i could understand how to gradually slow and speed up the animation this might work for me now. I'm also trying a different approach using an OnTriggerEnter and OnTriggerExit approach without any raycasting. Problem is still the gradual slowing and speeding up of the animation though.

avatar image meat5000 ♦ · Jan 19, 2015 at 11:43 AM 0
Share

You can change the speed of the Animation Layer with Animator.

http://docs.unity3d.com/ScriptReference/Animator-speed.html

I don't think you can change each Animation individually, but only the whole layer.

avatar image paulknight10 · Jan 19, 2015 at 04:16 PM 0
Share

thanks for the pointer towards the Animator component..However I still dont get how i access it to slow the animation speed in the script.

avatar image meat5000 ♦ · Jan 23, 2015 at 02:53 PM 0
Share

Animator wont work for you if you have done you animation in Legacy 'Animation' component.

Otherwise, using Animator, you can simply reference the animator in script, and set its speed.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by meat5000 · Jan 19, 2015 at 10:51 AM

Raycast is expensive. GetComponent is expensive. 'for this in that' is expensive. Debug is expensive.

Yes. This is probably the wrong approach, but try removing the print and Debug and see if that is the reason for bad performance.

Comment
Add comment · 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

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

Collision occurring when it should not! Help! 1 Answer

Passing values from Shader to C# script 0 Answers

Raycasting fail 1 Answer

Why does Physics2D.Capsule/Circle/BoxCast's hit point and distance not line up? 0 Answers

Raycasts hit triggers disabled - force collision for specific raycast 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