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 FPSworrior · Jan 19, 2014 at 12:50 AM · errorfix

4 Error on my script.

Scripts/aim 2.js(19,41): BCE0017: The best overload for the method 'UnityEngine.Vector3.Lerp(UnityEngine.Vector3, UnityEngine.Vector3, float)' is not compatible with the argument list '(UnityEngine.Quaternion, UnityEngine.Vector3, float)'.

Scripts/aim 2.js(19,41): BCE0022: Cannot convert 'UnityEngine.Vector3' to 'UnityEngine.Quaternion'.

Scripts/aim 2.js(25,41): BCE0017: The best overload for the method 'UnityEngine.Vector3.Lerp(UnityEngine.Vector3, UnityEngine.Vector3, float)' is not compatible with the argument list '(UnityEngine.Quaternion, UnityEngine.Vector3, float)'.

Scripts/aim 2.js(25,41): BCE0022: Cannot convert 'UnityEngine.Vector3' to 'UnityEngine.Quaternion'.

Can anyone fix these errors?

 #pragma strict
 
 var HipPose : Vector3; 
 var AimPose : Vector3;
 var HipRot : Vector3;
 var AimRot : Vector3;
 var AimSpeed = 0.5;
 
 function Start () 
 { 
   transform.localPosition = HipPose;
 } 
 
 function Update () { 
 
 if(Input.GetButton("Fire2"))
 { 
   transform.localPosition = Vector3.Lerp(transform.localPosition, AimPose, AimSpeed * Time.deltaTime);
   transform.localRotation = Vector3.Lerp(transform.localRotation, AimRot, AimSpeed * Time.deltaTime);
 } 
 
 if(!Input.GetButton("Fire2"))
 { 
   transform.localPosition = Vector3.Lerp(transform.localPosition, HipPose, AimSpeed * Time.deltaTime);
   transform.localRotation = Vector3.Lerp(transform.localRotation, HipRot, AimSpeed * Time.deltaTime);
 }
 }
Comment
Add comment · Show 2
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 iwaldrop · Jan 19, 2014 at 12:59 AM 0
Share

Use Quaternion.Lerp or the transform eular angles ins$$anonymous$$d of rotation. Rotation is a Quaternion, just as the error suggests.

avatar image FPSworrior · Jan 20, 2014 at 06:18 PM 0
Share

Ok I don't really understand what I have to change so can you re-write my script and change the things that I'm supposed to?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by thelackey3326 · Jan 20, 2014 at 08:29 PM

Expanding on what iwaldrop said:

Lines 19 and 25 are where the problem lies. There it looks like you are trying to interpolate ("lerp") a rotation, which is a Quaternion. The error is that you are using Vector3.Lerp() where you should be using Quaternion.Lerp().

 transform.localRotation = Vector3.Lerp(transform.localRotation, AimRot, AimSpeed * Time.deltaTime);

For line 19, it should probably be:

 transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(AimRot), AimSpeed * Time.deltaTime);

Just as a side note

Something you should keep in mind is that passing the value you want to interpolate as the from value will mean that the difference between from and to will become infinitely small but, theoretically, never quite reach zero. The effect is that the lerp will slow down over time but will never complete (if complete is the right word). It's not invalid, but it may not be the desired effect.

Comment
Add comment · Show 6 · 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 FPSworrior · Jan 20, 2014 at 08:49 PM 0
Share

Alright thanks for helping me out as well, I'll try using this.

avatar image FPSworrior · Jan 25, 2014 at 06:04 AM 0
Share

So I finally got time to try this but it doesn't work, I get this error;

/Scripts/aim 2.js(19,44): BCE0017: The best overload for the method 'UnityEngine.Quaternion.Lerp(UnityEngine.Quaternion, UnityEngine.Quaternion, float)' is not compatible with the argument list '(UnityEngine.Quaternion, UnityEngine.Vector3, float)'

/Scripts/aim 2.js(25,44): BCE0017: The best overload for the method 'UnityEngine.Quaternion.Lerp(UnityEngine.Quaternion, UnityEngine.Quaternion, float)' is not compatible with the argument list '(UnityEngine.Quaternion, UnityEngine.Vector3, float)'.

avatar image iwaldrop · Jan 25, 2014 at 07:31 AM 1
Share

Yeah. That would happen if you used the above code, because AimRot is a Vector3. Poorly named variable, because Vectors describe points and angles while Quaternions describe rotations. A better name for 'AimRot' would be 'ai$$anonymous$$gEulerAngle'. You might consider storing a Quaternion (although I'm not sure how that would impact the rest of your code, depending on how much you assigned the rotation calling Quaternion.Euler would add up in lost frames). That bit aside, this line should work with your existing setup:

 transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(AimRot), AimSpeed * Time.deltaTime);

As per the documentation, Quaternion.Euler returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).

avatar image FPSworrior · Jan 25, 2014 at 05:40 PM 0
Share

Thank you for the help I'll have to try this out, I'll let you know if I have any problems. By the way I don't think it matters what the variable is called it's just short for aim rotation.

avatar image iwaldrop · Jan 25, 2014 at 06:54 PM 1
Share

Of course it matters! :)

It's good program$$anonymous$$g practice for your (at least member) variable names to be meaningful. It's not a rotation, it's an angle. If it had been more clear then perhaps thelackey wouldn't have assumed it was a Quaternion. While it may not matter when only a single person is working on a code base, it is of utmost importance when multiple people are, and that the na$$anonymous$$g convention produces clear and meaningful information; self documenting code is the best kind.

Imagine getting someone else's code and not knowing what anything is because they just named things willy-billy off the top of their heads.

Show more comments

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

20 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

Related Questions

How to check collision with specific object 1 Answer

Fix this script? 0 Answers

NullReferenceException Error 2 Answers

Pause script errror. 1 Answer

how do i fix this error 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