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 H00D3DM4N2787 · Oct 09, 2014 at 05:19 AM · movemovingroomrooms

How to make a Script for moving rooms

Hi I'm Looking to make a script or series of scripts for moving rooms

basically theres the main room which is fixed and cannot move

how ever the rooms around it can follow certain trajectories based on its current position compared to its destination

i want to create a feel that wen the player does a something

he/she will feel the rooms and even see the rooms moving around the main building to the destination in question

ive tried for a while to figure this out

but no luck

i need help with a script that detects which destination or dock that the room in question currently occupies then i need a script that dictates the room in question's decided destination then i need a script that decides wat trajectories to take in order to get to said destination

i also need a script that says if the player is inside one of the moving rooms then the player moves with the room (as if on a moving platform)

now im not asking for someone to type up a script for me but if they could gimme some advice as to wat needs to be done how i should type it up and maybe event a link to somewhere i can find the answer for myself i just need a bit of help

and ill appreciate any help i can get

here are a few scripts ive tried yet cant get them to work as i want them to (if u can recommend a better script, id be so happy to lose these ones) [code=CSharp]using UnityEngine; using System.Collections;

public class MovingRoom : MonoBehaviour {

 public Transform mytransform;

 public Transform[] Target;

 public int targetnum;

 public int Current;

 public Transform[] Trajects;

 public MovingRoomCTRL roomctl;

 public int path;

 public float movespeed = 15;

 public float[] minepos;

 public float[] destpos;

 public int whichdestin;
 
 // Use this for initialization
 void Start () {
 
     mytransform = this.transform;

     roomctl = GameObject.Find ("Main").GetComponent <MovingRoomCTRL> ();

     Trajects = new Transform[5];
  
     Trajects [0] = GameObject.Find ("Traject1").transform;
     Trajects [1] = GameObject.Find ("traject2").transform;
     Trajects [2] = GameObject.Find ("traject3").transform;
     Trajects [3] = GameObject.Find ("Traject4").transform;
     Trajects [4] = GameObject.Find ("Traject5").transform;

     minepos = new float[3];

     minepos [0] = mytransform.position.x;
     minepos [1] = mytransform.position.y;
     minepos [2] = mytransform.position.z;

 }
 
     void Update () {

         if (roomctl.route){
         WhichDest ();
         setthepath ();
         Move ();
         }
     }

 public void WhichDest (){

     if (minepos [0] != roomctl.Dests [whichdestin].position.x && minepos [1] != roomctl.Dests [whichdestin].position.y && minepos [2] != roomctl.Dests [whichdestin].position.z) {
         whichdestin += 1;
     } else {Current = whichdestin;}

     if (whichdestin > 4)
         whichdestin = 0;
     }

 public void setthepath () {

     if (roomctl.selectedDest = roomctl.Dests [0]){
         path = roomctl.Destnum;}
     else if (roomctl.selectedDest = roomctl.Dests [1]){
         path = roomctl.Destnum;}

     if (path == 0 && Current == 2) {

         Target = new Transform[4];

         Target[0] = Trajects[3];
         Target[1] = Trajects[2];
         Target[2] = Trajects[1];
         Target[3] = roomctl.selectedDest;

     }
     else if (path == 1 && Current == 2) {
      
         Target = new Transform[4];
      
         Target[0] = Trajects[3];
         Target[1] = Trajects[2];
         Target[2] = Trajects[1];
         Target[3] = roomctl.selectedDest;
      
     }
 }

 public void Move () {


         mytransform.position = Vector3.MoveTowards (mytransform.position, Target[targetnum].position, movespeed * Time.deltaTime);
         Trajectories ();

     }

 public void Trajectories (){
 
 if (mytransform.position.y == Target [targetnum].position.y && mytransform.position.x == Target [targetnum].position.x && mytransform.position.z == Target [targetnum].position.z)
     targetnum += 1;

     if (mytransform.position.y == roomctl.selectedDest.position.y && mytransform.position.x == roomctl.selectedDest.position.x && mytransform.position.z == roomctl.selectedDest.position.z){
         roomctl.route = false;
         targetnum = 0;
     }
 }

}[/code]

[code=CSharp]using UnityEngine; using System.Collections;

public class MovingRoomCTRL : MonoBehaviour {

 public MovingRoom moverom;

 public bool route = false;

 public Transform[] Dests;

 public int Destnum;

 public Transform selectedDest;

 void Start () {

     moverom = GameObject.FindGameObjectWithTag ("Room").GetComponent <MovingRoom> ();

     Dests = new Transform[4];
  
     Dests [0] = GameObject.Find ("Dest1").transform;
     Dests [1] = GameObject.Find ("Dest2").transform;
     Dests [2] = GameObject.Find ("Dest3").transform;
     Dests [3] = GameObject.Find ("Dest4").transform;

     }

 void Update () {

     if (! route) {
         if (Input.GetKeyDown (KeyCode.A)) {
             Destnum = 0;
             route = true;
             }
         else if (Input.GetKeyDown (KeyCode.B)) {
             Destnum = 2;
             route = true;
         }
     } else {SelectDest ();}
 }

 public void SelectDest (){

     selectedDest = Dests [Destnum];

 }

} [/code]

P.S I must ask for only C# scripting i cant use javascript so please if u direct me to a tutorial or show me a script please please make sure its C# thank you again

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

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

2 People are following this question.

avatar image avatar image

Related Questions

automatic moving script 1 Answer

Moving the hand of my mesh and associated rotations 0 Answers

objects to move when picked up 0 Answers

iOS Tap to move?? 2 Answers

How to move an object in world with script 1 Answer


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