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 sam32x · Jan 21, 2012 at 02:44 AM · controlmultiple-objects

how to make another object do what i do but with a delay

heres my move script:

 var forwards : float = 0;
 var turn  : float = 0;
 var updown : float = 0;
 var maxspeed = 32;
 var minspeed = 0;
 var maxturn = 270;
 var minturn = -270;
 var maxupdown = 90;
 var minupdown = -90;
 
 function Update () {
 transform.Translate(Vector3.forward * Time.deltaTime * forwards);
 transform.Rotate(Vector3.forward * Time.deltaTime * turn);
 transform.Rotate(Vector3.right * Time.deltaTime * updown);
 
 if(Input.GetKey("w"))
 forwards += 0.2;
 
 if(Input.GetKey("s"))
 forwards -= 0.2;
 
 if(Input.GetKey("right"))
 turn -= 5;
 
 if(Input.GetKey("left"))
 turn += 5;
 
 if(Input.GetKey("up"))
 updown += 5;
 
 if(Input.GetKey("down"))
 updown -= 5;
 
 if(Input.GetKey("e")){
 turn /= 1.1;
 updown /= 1.1;
 }
 
 if (forwards >= maxspeed)
 forwards = maxspeed;
 
 if (forwards <= minspeed)
 forwards = minspeed;
 
 if (turn >= maxturn)
 turn = maxturn;
 
 if (turn <= minturn)
 turn = minturn;
 
 if (updown >= maxupdown)
 updown = maxupdown;
 
 if (updown <= minupdown)
 updown = minupdown;
 }

anyone know how i can edit that and put it on another spaceship and have it follow me? like do everything i do but after

Comment
Add comment · Show 1
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 · Jan 21, 2012 at 09:27 AM 0
Share

It's very likely that what you want to do is very simply:

each time, $$anonymous$$OVE the following object, a little closer to you. And then use the incredibly handy "LookAt" function, which you will have to learn about.

In this way it will appear to follow you around the room.

If you truly want the other objects to REPEAT YOUR ACTIONS, that is difficult. I recommend you implement the first solution first and see how you go from there.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Jan 21, 2012 at 11:27 AM

If you just want to make a slave object to follow the master movements and rotations with some delay, you can use something like this (slave script):

var master: Transform; // drag the master object here var delay: float = 0.6;

private var offsetPos: Vector3; private var startRot: Quaternion; private var masterRot: Quaternion;

function Start(){ // save the initial positions/rotations offsetPos = transform.position - master.position; startRot = transform.rotation; masterRot = master.rotation; }

function LateUpdate(){ var targetPos = offsetPos + master.position; var targetRot = Quaternion.Inverse(masterRot) master.rotation startRot; var dT = Time.deltaTime / delay; transform.position = Vector3.Lerp(transform.position, targetPos, dT); transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, dT); } The slave object follows the master object's position and rotation smoothly, and the delay parameter adjusts how slowly it does it.
This is not an actual delay. If you really need a fixed delay between the master and the slave, things become more complicated: you must use a couple of arrays to store master position/rotation at regular intervals, and get the slave position/rotation from N elements behind the last element stored.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Reversed Controls? 2 Answers

Help with iphone/android touch controls 2 Answers

Camera Control and Character Rotation 1 Answer

Input Help! 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