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 Weirdo-Studios · Jul 01, 2013 at 04:26 PM · animationfpslerpvectorsway

Vector3.Lerp and Animations

So I have my weapon and a gun sway script but i also have some animations which are constantly playing (idle, walk, sprint, aim). I think that there is some issue with the animations overriding the vector3.lerp. If not then please tell me why this isn't working. But if anyone has any idea how to have the lerp and the animations that would be great. Here is the Code

 public var MoveAmount : float = 1;
 public var MoveSpeed : float = 2;
 public var Gun : GameObject;
 public var MoveOnX : float;
 public var MoveOnY : float;
 public var DefaultPos : Vector3;
 public var NewGunPos : Vector3;
 
 function start () {
     DefaultPos = transform.localposition;
 }
 
 function Update () {
 
     MoveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * MoveAmount;
     MoveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * MoveAmount;
     NewGunPos = new Vector3 (DefaultPos.x+MoveOnX,DefaultPos.y+MoveOnY, DefaultPos.z);
     Gun.transform.localpostion = Vector3.Lerp(Gun.transform.localPosition, NewGunPos , MoveSpeed * Time.deltaTime);
 }
Comment
Add comment · Show 3
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 pickle chips · Jul 01, 2013 at 04:29 PM 0
Share

What is the script with the animations?

avatar image Weirdo-Studios · Jul 02, 2013 at 07:56 AM 0
Share

Sorry at the moment I am at school and do not have access to the code as soon as i get back i'll upload it here.

avatar image Weirdo-Studios · Jul 02, 2013 at 03:14 PM 0
Share

Here it is, this probably isn't the best way to do the animation but I wrote and figured this one myself so... yeah.

 var sprinting : boolean = false;
 var walking : boolean = false;
 var Player$$anonymous$$otor : Character$$anonymous$$otor;
 var SprintSpeed : float = 12;
 var WalkSpeed : float = 6;
 var PlayerController : CharacterController;
 var PlayerVelocity;
 var Ai$$anonymous$$g : boolean = false;
 
 //animation
 function Update () 
 {    
     //set player velocity the same as controller
     PlayerVelocity = PlayerController.velocity.magnitude;
     //check ai$$anonymous$$g
     if (Input.Get$$anonymous$$ouseButtonUp(1))
     {
         Ai$$anonymous$$g = false;
     }
     
     // see if walking is off
     if (Input.GetAxis("Vertical")== 0)
     {
         walking = false;
     }
     
     // see if walking is off
     if (Input.GetAxis("Horizontal")== 0)
     {
         walking = false;
     }
     
     //check if sprinting is off
     if (Input.GetButtonUp("Sprint"))
     {
         sprinting = false;
     }
     //if ai$$anonymous$$g is on
     if (Input.Get$$anonymous$$ouseButtonDown(1))
     {
         Ai$$anonymous$$g = true;
     }
         
     //check if walking is on
     if (Input.GetAxis("Horizontal"))
     {
         walking = true;
     }
     
     //check if walking is on
     if (Input.GetAxis("Vertical"))
     {
         walking = true;
     }
     //check if sprint is on
     if (Input.GetButtonDown("Sprint"))
     {
         sprinting = true;
     }
     
     //is ai$$anonymous$$g is on
     if (Ai$$anonymous$$g == true)
     {
         sprinting = false;
         animation["Ai$$anonymous$$gInIdle"].speed = 1+(PlayerVelocity/WalkSpeed);
         animation.CrossFade("Ai$$anonymous$$gInIdle", 0.4);
         //change speed
         Player$$anonymous$$otor.movement.maxForwardSpeed = WalkSpeed/0.8;
         Player$$anonymous$$otor.movement.maxBackwardsSpeed = WalkSpeed/2;
         Player$$anonymous$$otor.movement.maxSidewaysSpeed = WalkSpeed/1.5;
     }
     
     //if sprinting is on play anim
     else if (sprinting == true)
     {
         walking = false;
         animation["Sprint Animation"].speed = PlayerVelocity/SprintSpeed;
         animation.CrossFade("Sprint Animation", 0.2);
         //change speed
         Player$$anonymous$$otor.movement.maxForwardSpeed = SprintSpeed;
         Player$$anonymous$$otor.movement.maxBackwardsSpeed = SprintSpeed/2;
         Player$$anonymous$$otor.movement.maxSidewaysSpeed = SprintSpeed/1.5;
     }
     
     //if not check if walking is on if it is play anim
     else if(walking == true)
     {
         animation["Walking Animation"].speed = PlayerVelocity/WalkSpeed;
         animation.CrossFade("Walking Animation",0.3);
         //change speed
         Player$$anonymous$$otor.movement.maxForwardSpeed = WalkSpeed;
         Player$$anonymous$$otor.movement.maxBackwardsSpeed = WalkSpeed/2;
         Player$$anonymous$$otor.movement.maxSidewaysSpeed = WalkSpeed/1.5;
     }
     
     //if all are false then playu idle
     else 
     {
         animation.CrossFade("Idle Animation",0.3);
     }
 
 }
 

0 Replies

· Add your reply
  • Sort: 

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

16 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

Related Questions

Lerping Field Of View is buggy 1 Answer

Learning to move 1 Answer

How to make an Animation movement happen only after certain keyframes? 0 Answers

animating multiple weapons with 2 arms 0 Answers

Smooth animation scrubbing with the mouse 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