Ive got an object that constantly moves forward (be it, at a vector or target)
Now, i want its movement to be going in a ZIGZAG, forward. Essentially i would end up with a snake like movement, an S shape.
Problem is, with the coding ive used and itween events, it appears there is no easy logical way to update the position for two different movements.
Hey guys,
not sure if this will help anyone, but here is the code im personally using so far.
Theres still a problem with origin positions/angles, but its still alright.
(made some minor edits to the code within the link savlon provided)
#pragma strict
var MoveSpeed = 5.0f;
var frequency = 20.0f; // Speed of sine movement
var magnitude = 0.5f; // Size of sine movement
var axis : Vector3;
var pos : Vector3;
var player : Transform;
function Start () {
transform.LookAt(player);
pos = transform.position;
//DestroyObject(gameObject, 1.0f);
axis = transform.up; // May or may not be the axis you want
}
function Update () {
pos += transform.forward * Time.deltaTime * MoveSpeed;
transform.position = pos + axis * Mathf.Sin (Time.time * frequency) * magnitude;
}