- Home /
Rotation via iTween.LookTo not working (or using it wrong)
Hello All,
I'm currently trying to get GameObject A to look at or rotate towards GameObject B. But, the iTween function doesn't seem to rotate GameObject A correctly. Or what I need, maybe it is rotating correctly but not what I need. The game is 2D. GameObject A picks a random position outside of the bounds of the screen, teleports there, then it should rotate towards GameObject B(so when it moves on screen it should appear to be looking directly towards GameObject B, and moves towards GameObject B. But GameObject A is always looking towards the top part of the screen.
Please help, and let me know if more information is need or more explanation.
// Animate the fly to the target node
protected override void flyToTarget()
{
if (targetTile.pickupItem == null)
{
_state = StarThiefState.leaving;
gameObject.SetActiveRecursively(false);
return;
}
MHSoundController.playLoopingSFX(seekSound);
transform.position = positionOutsideOfBoard();
sprite.PlayAnim(sprite.defaultAnim);
Vector3 starPosition = targetTile.transform.position;
//starPosition.y += transform.position.y;
starPosition.z += 30;
//rotate and look at target TODO doesn't work
// Rotate it in the proper direction
iTween.LookTo(spaceShipIdle.gameObject, iTween.Hash("looktarget", targetTile.transform.position, "axis", "y"));
//move to target
iTween.Stop(gameObject);
iTween.MoveTo(gameObject, iTween.Hash("position", starPosition, "speed", speed, "easetype", "easeOutSine", "oncompletetarget", gameObject, "oncomplete", "landedOnTarget"));
}
@AT$$anonymous$$Ethan
$$anonymous$$ate got to thank you here, I'm new to iTween and I was struggling to get iTween.LookTo() to work but your script provided the working example I was desperately seeking.
Cheers buddy!
Hi, i'm struggling with LookTo feature as well. Do you have any idea why this code doesn't work?
using UnityEngine;
using System.Collections;
public class PathCam : $$anonymous$$onoBehaviour
{
void Start(){
iTween.$$anonymous$$oveBy(gameObject, iTween.Hash(
"x",3,
"y",2,
"z",2,
"easeType", "easeInOutExpo",
"loopType", "pingPong",
"delay", .1
));
iTween.LookTo(gameObject, iTween.Hash (
"looktarget", Eski$$anonymous$$asa.transform.position,
));
}
}
Above script gives me this error but i have no idea how to fix.
Answer by ATMEthan · Feb 07, 2013 at 08:15 PM
...shame on me. It's because of the art asset I was using. It was rotated 90 degrees to the right, hence making the rotation seem wrong. Once, I get the my new art assets I'll verify if it was actually the art asset or not.