Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by MrSteve1 · Feb 01, 2016 at 07:10 PM · lerplocalscale

Should be easy.....

Hi All,

I am writing a simple code, which was working fine up until about an hour ago.

Below is the script and I will explain what is wrong afterwards.

 @Header("Fidget Attributes")
 var state : boolean;
 var scale : float;
 private var t : float;
 var speed : float;
 @Header("Bounce Attributes")
 var force : float;
 var isGrounded : boolean = true;
 
 @Header("Shift Attributes")
 var portalOne : GameObject;
 var portalTwo : GameObject;
 var portalsPlaced : int;
 var keyDown : boolean;
 
 @Header("Global Variables")
 var ballController : PlayerBallControl;
 var playerController : PlayerController;
 
 function Start () 
 {
     ballController = GetComponent.<PlayerBallControl>();
     playerController = gameObject.FindWithTag("IGG").GetComponent.<PlayerController>();
 }
 
 function Update()
 {
     Fidget();
     gameObject.Find("Fidget").transform.localScale = Vector3(scale,scale,scale);
 }
 
 function LateUpdate () 
 {
     
     if(ballController.goodToGo)
     {
         if(Input.GetKeyDown(KeyCode.Space))
         {
             if(playerController.currentPlayer == "Fidget")
             {            
                 if(!state || state)
                 {
                     state = !state;
                     t = 0;
                 }
             
             }//End Fidget
             
             if(isGrounded && playerController.currentPlayer == "Bounce")
             {
                 gameObject.Find("Bounce").GetComponent.<Rigidbody>().velocity.y = 0;
                 gameObject.Find("Bounce").transform.position.y = gameObject.Find("Bounce").transform.position.y + 0.3;
                 gameObject.Find("Bounce").GetComponent.<Rigidbody>().AddForce(Vector3.up * force);
                 isGrounded = false;
             }//End Bounce
         }//End Spacebar
             if(playerController.currentPlayer == "Shift")
             {
                 if(Input.GetKeyDown(KeyCode.Space) && portalsPlaced > 0)
                 {
                     if(gameObject.FindWithTag("Portal1"))
                     {
                         Destroy(gameObject.FindWithTag("Portal1"));
                         portalsPlaced--;
                     }
                     if(gameObject.FindWithTag("Portal2"))
                     {
                         Destroy(gameObject.FindWithTag("Portal2"));
                         portalsPlaced--;
                     }
                     if(GetComponent.<Collider>().enabled == false)
                         GetComponent.<Collider>().enabled = true;
                 }
                 if(Input.GetKeyDown(KeyCode.F))
                 {
                     if(portalsPlaced == 0)
                     {    
                         Instantiate(portalOne,Vector3(gameObject.Find("Shift").transform.position.x,gameObject.Find("Shift").transform.position.y - 0.4,gameObject.Find("Shift").transform.position.z),Quaternion.identity);
                         keyDown = true;
                         portalsPlaced ++;
                     }
                     else
                     keyDown = false;
                     if(portalsPlaced == 1 && !keyDown && !gameObject.FindWithTag("Portal2"))
                     {
                         Instantiate(portalTwo,Vector3(gameObject.Find("Shift").transform.position.x,gameObject.Find("Shift").transform.position.y - 0.4,gameObject.Find("Shift").transform.position.z),Quaternion.identity);
                         portalsPlaced ++;
                     }
                     if(portalsPlaced == 1 && !keyDown && gameObject.FindWithTag("Portal2"))
                     {
                         Instantiate(portalOne,Vector3(gameObject.Find("Shift").transform.position.x,gameObject.Find("Shift").transform.position.y - 0.4,gameObject.Find("Shift").transform.position.z),Quaternion.identity);
                         portalsPlaced ++;
                     }
                 }
             }//End Shift
     }
 
 }
 
 function Fidget()
 {
     
     if(!state)
     {
         if(t<1)
             t+= Time.deltaTime * speed;
         scale = Mathf.Lerp(0.3,1,t);
     }
     else
     {
         if(t<1)
             t+= Time.deltaTime * speed;
         scale = Mathf.Lerp(1,0.3,t);
     }
 }
 
 function OnCollisionStay(hit:Collision)
 {
     if(gameObject.name == "Bounce")
     {
         for (var contact : ContactPoint in hit.contacts)
         {
             if(hit.gameObject.tag == "Floor" && contact.normal.y > 0.6)
                 isGrounded = true;
         }
     }
 }
 
 function ClearPortal()
 {
     portalsPlaced --;
 }
 

Most of this works fine, but you see the only line of code in the Update() Function? It no longer works. all it has to do is find the gameObject names Fidget which it does fine, and transform its local scale based on the variable "scale". But it doesn't!!! The variable scale changes when I hit space bar as it should (It lerps between 0.3 and 1) but the size of my object remains the same and will not change from 0.3 anymore.

Can someone point of the error I have made. I have read the whole script three times now!

Thanks

Steve

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 MrSteve1 · Feb 01, 2016 at 08:04 PM 0
Share

Slight update to this, still not working, but look at line 29....

--> += Vector3 works, but =Vector3 does not. Please help!!

avatar image Jessespike · Feb 01, 2016 at 08:09 PM 0
Share

The script works, so something else is going on here. I'm thinking the game object is set to static and it's being batched. Other ideas are to check the global time scale and check if there are more than one object Fidget.

avatar image MrSteve1 Jessespike · Feb 02, 2016 at 03:16 PM 0
Share

Hi Jess,

Thank you for your response, however all things are okay. Fidget is the only one in the scene and it is not static. The Time scale is also okay as it can be controlled just fine.

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

33 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 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

Smooth camera to target Y-height 3 Answers

C# Lerping Problem 0 Answers

Player movement 0 Answers

How to Slerp / Lerp Rotation on a Single Axis? 0 Answers

Final position of the camera movement 0 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