If anyone knows what i am messing up here it would be really appreciated.
Ok so my game is in 2d and has a lot of little baddies that just do a basic back and fourth along x
for both my main character and all the baddies, I basically have them set up as a parent that has all the controls. The graphic is a child with just sprite manager2.
My main character is working fine since his direction is based of the movement controlled but the virtual joystick
However, I cant figure out how to get the bad guys to rotate based on movement like the main guy does.
Here are my two scripts
- the basic script for bad guy to go back and fourth on the Parent.
var targetA : GameObject;
var targetB : GameObject;
var speed : float = 0.1;
function Update () {
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);
}
- my script that is on the child SM2 object for snapping back and fourth based on movement.
I select the parent that is moving for my variable but it doesnt work.
var rb : Rigidbody;
private var moveDirection : Vector3 = Vector3.zero;
function Update () {
if ( rb.velocity.x > 0 ) {
transform.eulerAngles = Vector3(0,0,0);
}
if ( rb.velocity.x < 0 ) {
transform.eulerAngles = Vector3(0,180,0);
}
}
Thanks a bunch if anyone can help