- Home /
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
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.
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.
Your answer
Follow this Question
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