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 kageoushou · Jan 07, 2014 at 10:10 PM · movementmovement scriptplatform

Platform Mover continued

Hi everyone fixed my platform script working pretty well however I want to make the platform stay at its beginning and end positions for a little while instead of the platform going back and forth on a loop and was wondering what script i would need or what I could add to my platform mover script to make that happen

Thanks

Here is the Script

 #pragma strict
 
 
 var Xpos : float;
 var Ypos : float;
 var max : boolean;
 
 var Vert : boolean;
 var maxAmount : int;
 var step : float;
 
 function Start () {
     Xpos = transform.position.x;
     Ypos = transform.position.y;
 }
 
 function Update () {
     //Set the Max
     if(Vert){
         if(transform.position.y >= Ypos + maxAmount){
         max = true;
         } else if(transform.position.y <= Ypos){
             max = false;
         }
     } else {
         if(transform.position.x >= Xpos + maxAmount){
             max = true;
         } else if(transform.position.x <= Xpos){
             max = false;
         }
     }
     
     //Moving Platform
     if(Vert){
         if(!max){
             transform.position.y += step;
         } else {
             transform.position.y -= step;
 
         }
     } else {
         if(!max){
             transform.position.x += step;
         } else {
             transform.position.x -= step;
         }
     }
 
 }
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 Sericet1 · Jan 07, 2014 at 10:15 PM 0
Share

What if you made a boolean to test to see if your at the max position, and used the WaitForSecond() before the platform moves again.

avatar image kageoushou · Jan 11, 2014 at 10:49 PM 0
Share

sorry pretty new to Unity how would i write that in script form

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kageoushou · Jan 14, 2014 at 08:57 AM

found this moving platform script on unify wiki however getting an error on line 68

'transform' is not a member of 'Object'.

anyway here is the script

 #pragma strict
 
 class Route{
     var distance : Vector3 = Vector3(0,0,0);
     var speed : Vector3 = Vector3(-1,-1,-1); // Put a negative number to use the default value.
     var waitTime : float=-1; // Put a negative number to use the default value.
 }
  
 var reverseAtEnd : boolean = true; // Reverse the route when it ends, example TODO
 var speedDefault : Vector3 = Vector3(0,0,0); // Must be positive
 var waitTimeDefault : float =  1.0f;
 var route : Route[] = new Route[1];
  
 private var distanceNow : Vector3;
 private var speedNow : Vector3;
 private var waitTimeNow : float = 0f;
 private var waitUntil : float = 0f;
 private var index : int = -1;
 private var routeIndex : int = 0;
 private var way : int = 1;
 private var destiny = Vector3(0,0,0);
 private var objectsInPlatform : Array = new Array();
  
 function Start(){
     if (route.Length==0)
         Debug.Log("MovingPlatform: ERROR! NO ROUTE DEFINED!");
     destiny = transform.position;
     objectsInPlatform.Add(gameObject);
 }
  
 function Update(){
     if(waitUntil>=0){ // If is waiting. In the first call, go to this part.
         if(waitUntil>Time.timeSinceLevelLoad){
             // Keep waiting
             return;
         }else{
             // Stops waiting and prepares the next index
             waitUntil=-1;
             index++;
             if(index==route.length){
                 index=0;
                 if(reverseAtEnd) 
                     way *= -1;
             }    
             routeIndex = (way==1) ? index : (route.length - 1 - index);
             distanceNow = route[routeIndex].distance;
             speedNow = (route[routeIndex].speed==null || route[routeIndex].speed[0]<0 || route[routeIndex].speed[1]<0
                 || route[routeIndex].speed[2]<0) ? speedDefault : route[routeIndex].speed;
             for(var dv : int = 0;dv<3;dv++){ // Calculates the way of velocity with basis of distance.
                 speedNow[dv] *= (distanceNow[dv]*way>0.0) ? 1 : -1;
             }
             waitTimeNow = (route[routeIndex].waitTime<0) ? waitTimeDefault : route[routeIndex].waitTime;
             destiny = distanceNow*way+transform.position;
         }    
     }
     //Calculates the distance to go.
     var distanceToGo : Vector3 = speedNow*Time.deltaTime; 
     var destinyWithoutFix : Vector3 = distanceToGo+transform.position;
     for(var d : int = 0;d<3;d++){
         distanceToGo[d] = (distanceToGo[d]>0) ? 
             Mathf.Min(destinyWithoutFix[d],destiny[d]) : Mathf.Max(destinyWithoutFix[d],destiny[d]);
     }
     distanceToGo-=transform.position;
  
     // Move the objects
     for(var i : int = 0;i<objectsInPlatform.length;i++){ 
         if(objectsInPlatform[i]){
             objectsInPlatform[i].transform.position+=distanceToGo;
         }else{
             objectsInPlatform.RemoveAt(i);
             i--;
         }
     }
  
     // Self explain
     if(destiny==transform.position)
         waitUntil = Time.timeSinceLevelLoad+waitTimeNow;
 }
  
 function OnTriggerEnter(collider : Collider){
     //Debug.Log("MovingPlatform OnTriggerEnter "+collider.gameObject);
     AddObject(collider);
 }
  
 function OnTriggerExit(collider : Collider){
     //Debug.Log("OnTriggerExit");
     RemoveObject(collider);
 }
  
 function OnCollisionEnter(collision : Collision) {
     //Debug.Log("MovingPlatform OnCollisionEnter "+collision.collider.gameObject);
     AddObject(collision.collider);
 }
  
 function OnCollisionExit(collision : Collision) {
     //Debug.Log("OnCollisionExit");
     RemoveObject(collision.collider);
 }
  
 function AddObject(collider : Collider) {
     objectsInPlatform.Add(collider.gameObject);
 }
  
 function RemoveObject(collider : Collider) {
     // Starts on 1 because that position 0 is always this gameObject  
     for(var i : int = 1;i<objectsInPlatform.length;i++){ 
         if(objectsInPlatform[i]==collider.gameObject){
             objectsInPlatform.RemoveAt(i);
             i--;
         }
     }
 }
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

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

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

Moving platform script makes my player unable to move 3 Answers

Character on Moving and Rotating Platform 0 Answers

Child object not moving with parent 3 Answers

Issue with Collisions due to Parenting script 0 Answers

Forward movement rotated on movement script? 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