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 /
This question was closed Dec 05, 2013 at 02:02 AM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ham · Aug 29, 2013 at 06:57 PM · movementlerp

moving a gamobject in vacum

hi guys i have a gameobject that moves up and down and right and left slowly , like vacum movement this is the code ive written , it runs when the movingtime parameter is true but it doesnt work correctly because of moving time boolean is always true and it hasnt got smooth movement

 function MoveInVacum()
 {
     MovingTime = false ;
     NextMoveForX = Random.Range(StartPointXLeft , StartPointXRight);
     NextMoveForY = Random.Range(StartPointYDown , StartPointYUp);
     NextPoint.x =  transform.position.x ;
     NextPoint.y = NextMoveForY ;
     NextPoint.z = transform.position.z ;
     this.transform.position = Vector3.Lerp(this.transform.position,  NextPoint, .02 * Time.deltaTime);
     //print(NextMoveForX);
     //yield WaitForSeconds (1);
     MovingTime = true ;
 }

so , would anyboy please correct my plan for solving this problem , thanx

Comment
Add comment · Show 7
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 clunk47 · Aug 29, 2013 at 07:05 PM 1
Share

Use two functions ins$$anonymous$$d of one. Use one function that will only switch the boolean from true to false, vice versa. I'd use the actual movement code inside of Update() function.

$$anonymous$$ovingTime = !$$anonymous$$ovingTime

Will toggle the boolean.

avatar image clunk47 clunk47 · Aug 30, 2013 at 04:17 PM 1
Share

You don't have your if() statements in any function. Place them inside of Update().

avatar image clunk47 clunk47 · Aug 30, 2013 at 04:18 PM 1
Share

And as I stated in my answer, place your true and false statements in a different function.

avatar image ham clunk47 · Aug 30, 2013 at 05:01 PM 1
Share

you are right , thanx alot

Show more comments

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by Eric5h5 · Aug 30, 2013 at 05:20 PM

I'm not quite sure what you're actually trying to do, but I'm sure it would be far easier with coroutines in any case:

 var startPointXLeft = -5.0;
 var startPointXRight = 5.0;
 var startPointYDown = -5.0;
 var startPointYUp = 5.0;
 var moveSpeed = 5.0;
 
 function Start () {
     while (true) {
         var nextMoveForX = Random.Range(startPointXLeft, startPointXRight);
         var nextMoveForY = Random.Range(startPointYDown, startPointYUp);
         var originalPoint = transform.position;
         yield Move(Vector3(transform.position.x, nextMoveForY, transform.position.z));
         yield Move(originalPoint);
         yield Move(Vector3(nextMoveForX, transform.position.y, transform.position.z));
     }
 }
 
 function Move (nextPoint : Vector3) {
     var startPoint = transform.position;
     var rate = 1.0 / Vector3.Distance(nextPoint, startPoint) * moveSpeed;
     var t = 0.0;
     while (t < 1.0) {
         t += Time.deltaTime * rate;
         transform.position = Vector3.Lerp(startPoint, nextPoint, t);
         yield;
     }
 }
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 ham · Sep 10, 2013 at 04:14 AM 0
Share

give me a short time to check it , ill feedback you then, right now just thanx and more

avatar image
0

Answer by roojerry · Aug 30, 2013 at 05:08 PM

Are you looking for it to slowly move back and forth and up and down? Mathf.PingPong() might be better for you to use than just getting random values

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Lerp Movement Forward Help 2 Answers

Movement Script 1 Answer

Coroutine Moving 1 Answer

Vector3.lerp causes gameobject to move thousands of pixels away from where it's mean to go 1 Answer

Everything is choppy... How can I make object movement more fluid? 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