- Home /
automatic moving script
i trying to make a script so that a cube or more go from one to another and back how do i do it??
Answer by Graham-Dunnett · Nov 29, 2011 at 02:13 PM
var targetA : GameObject;
var targetB : GameObject;
var speed : float = 0.1;
function FixedUpdate () {
var weight = Mathf.Cos(Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5;
transform.position = targetA.transform.position * weight
+ targetB.transform.position * (1-weight);
}
This code animates an object between two points identified by the targetA and targetB game objects which you can set in the inspector. (Stolen from the 2D platformer tutorial.)
Thanks a lot, I had a similar trouble, solved with your help. Thanks.
Your answer
Follow this Question
Related Questions
Triggered box works automatically for OnMouseEnter for objects inside. 0 Answers
Moving Platform Collisions with Custom Movement Script 0 Answers
How Come My Walking Script Doesn't Move the Character Forward? 1 Answer
charactercontroller.isgrounded not working!! 1 Answer
Trying out a unique method of spawning enemies. Someone want to help sort out the logic of it? 1 Answer