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 LightSource · Aug 13, 2013 at 03:07 AM · javascripttransformlerp

Object lerping at start

My script allows me, when I hit a certain point, to lerp to a certain position. At the start the object lerps to -15 on the x value which should only happen when the object is less then -17 on the x value which it is not. If anyone can help it would be much appreciated.

 //Original Object
     var object : GameObject;
 
 //Object position + end poition modified
     var objectPos : Vector3;
     var objectEnd : Vector3;
 
 //Controllers
     var duration : float = 1.0;
     var startTime : float;
 
 //Barriers
     var topPos : float = 1;
     var rightPos : float = 5;
     var leftPos : float = -12;
     var bottomPos : float = -17;
 
     function Start () {
 
     startTime = Time.time;
     objectPos = object.transform.position;
     objectEnd = object.transform.position;
 
     }
 
     function Update () {
 
     if (object.transform.position.x >= rightPos) {
 
        objectEnd.x = 4;
 
        object.transform.position = Vector3.Lerp(objectPos, objectEnd, (Time.time - startTime) / duration);
 
        }
        
     if (object.transform.position.x <= leftPos) {
 
        objectEnd.x = -10;
 
        object.transform.position = Vector3.Lerp(objectPos, objectEnd, (Time.time - startTime) / duration);
 
        }
        
          if (object.transform.position.y <= topPos) {
 
        objectEnd.y = -1;
 
        object.transform.position = Vector3.Lerp(objectPos, objectEnd, (Time.time - startTime) / duration);
 
        }
        
          if (object.transform.position.x <= bottomPos) {
 
        objectEnd.x = -15;
 
        object.transform.position = Vector3.Lerp(objectPos, objectEnd, (Time.time - startTime) / duration);
 
        }
 
     }
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 getyour411 · Aug 13, 2013 at 03:26 AM 0
Share

I don't see anything wrong with the line that's evaluating x to LE bottomPos; are there other scripts that might be applying force/gravity/movement onto this GO?

avatar image LightSource · Aug 13, 2013 at 04:46 AM 0
Share

Nope, just the one. I have even isolated it so its the only thing running, and without mouse clicks, it moves like it should but without purpose.

avatar image highpockets · Aug 13, 2013 at 06:07 AM 0
Share

Does you object start at a x position of 0 or 1?

1 Reply

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

Answer by robertbu · Aug 13, 2013 at 06:33 AM

The most likely cause of your specific issue is a value different in the inspector than the value you have in the code. By default in Javascript class variables are public, so topPos, rightPos, leftPos and bottomPos are all public and can be viewed in the inspector. The values you set in code for these variables are only used once when the component is attached. Changes to these values in the script does not change the values you see in the inspector. If this is your problem, you can do a couple of things. First, you can just set the values you want in the inspector, second, you can make the variables private, or third you can reset the values. To reset the values, select the game object in the hierarchy, in the inspector on the right side of your script component, click on the gear drowdown and select 'Reset'.

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 LightSource · Aug 13, 2013 at 03:48 PM 0
Share

I can't thank you enough, robertbu. Resetting the values helped.

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

17 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

Related Questions

Unity cannot use Vector3 error = confusion 1 Answer

I'm not sure what type a variable is and what to save it as. 2 Answers

How to smoothly rotate to certain directions using input axis 1 Answer

modifing enemies target inside a radius 1 Answer

Lerp position with curved paths 2 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