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 MickM · May 09, 2013 at 05:08 AM · texturedelaymaintexture

Delay after setting mainTexture

Gday all,

I am having trouble with a quick project I am trying to finish off in the next few hours... It isnt game breaking but it is a bit annoying.

Webplayer: https://dl.dropboxusercontent.com/u/74159983/Frogpad/Frogpad.html

It is a basic boardgame where you play a frog, after you roll, the frog jumps to the next square. I am simulating a jump just by changing textures but for some reason there is a very noticeable (2-3 second) delay between changing the texture and executing the next part of the code. (Immediately evident if you look at webplayer)

The code I am using is:

currentPlayerScript

 function Start () {
     renderer.material.mainTexture = normalFrog;
 }
 
 function Update () {
 
 }
 
 function Jump(){
     renderer.material.mainTexture = jumpingFrog;
 }
 
 
 function Land () {
     renderer.material.mainTexture = normalFrog;
 }
 
 function Splash () {
     renderer.material.mainTexture = splashFrog;
 }
 
 function SetPlayer(){
     isHuman = true;
 }


Key part of movement function

 currentPlayerScript.Jump();
 
 var distCovered = (Time.time - startTime) * moveSpeed;
 var fracJourney = distCovered - distanceToMove;
 
 while (!done){
     distCovered = (Time.time - startTime) * moveSpeed;
     fracJourney = distCovered - distanceToMove;
     currentPlayer.position = Vector3.Lerp(startLocation, moveLocation, fracJourney);
     yield;
     if (fracJourney > 0.99){
         done = true;
         currentPlayerScript.currentSquare = newPos;
         }
 }



Full function in movement script

 function MoveCharacter(i : int){
     turnState = 2;
     
     var newPos = currentPlayerScript.currentSquare + i;
     if (newPos > boardSquares.Count - 1){
         newPos = boardSquares.Count - 1;
         }
     if (newPos < 0){
         newPos = 0;
         }
     
     var moveLocation = boardSquares[newPos].transform.position;
     moveLocation += currentPlayerScript.safetyOffset;
     var distanceToMove = (currentPlayer.position - moveLocation).magnitude;
     var startLocation = currentPlayer.position;
     
     var moveSpeed = 1;
     var startTime = Time.time;
     
     var done = false;
     
     currentPlayerScript.Jump();
     
     var distCovered = (Time.time - startTime) * moveSpeed;
     var fracJourney = distCovered - distanceToMove;
     
     while (!done){
         distCovered = (Time.time - startTime) * moveSpeed;
         fracJourney = distCovered - distanceToMove;
         currentPlayer.position = Vector3.Lerp(startLocation, moveLocation, fracJourney);
         yield;
         if (fracJourney > 0.99){
             done = true;
             currentPlayerScript.currentSquare = newPos;
             }
     }
     
     if (boardSquares[newPos].waterSquare){
         currentPlayerScript.Splash();
         moveMod = -1;
         RunTurn();
     }
     else { 
         currentPlayerScript.Land();
         moveMod = 1;
         EndTurn();
         }
     
     
 }


I have no idea why it is doing this other than maybe a delay with changing the texture, but the actual texture change is instant... it is the delay afterwards which confuses me (I would have thought if there would be a delay, it would be as the texture was changing, not afterwards?)

Any help is greatly appreciated!

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 Fattie · May 09, 2013 at 05:47 AM 0
Share

FTR you have confusing yield statements I don't understand. Did you copy this code from somewheres or did you write it from scratch?

for simple timers in Unity, usually just use Invoke() or InvokeRepeating(). there are 1000000000s examples onhere, also unityGE$$anonymous$$S.com for beginner articles.

i answer to your question, simply add a few Debug.Log("i am here")l statements throughout your code (in the loops especially) and you will find the problem in one $$anonymous$$ute

hope it helps

avatar image MickM · May 09, 2013 at 07:20 AM 0
Share

The yield commands are there in loops, otherwise it will cause a crash.

All the standard debug stuff I have tried - the thing I dont get is why there is a delay between changing the texture and moving...

Thanks for the comment though.

1 Reply

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

Answer by whydoidoit · May 09, 2013 at 06:08 AM

Your Lerp is wrong, it looks like it's to do with the calculation of fracJourney which should be:

  fracJourney = distCovered/distanceToMove;
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 MickM · May 09, 2013 at 07:23 AM 0
Share

Thanks heaps! I have no idea how that happened as I copied from the unity docs... Damn gremlins!

Thankyou very much!!!

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

15 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

Related Questions

Assigning UV Map to model at runtime 0 Answers

Finding a list of properties in Shaders 1 Answer

Are extremely high load times for Procedural materials normal? 0 Answers

GUI movie texture - sound delay 1 Answer

Video texture problem? 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