- Home /
Question by
Shindy117 · Apr 14, 2017 at 03:50 PM ·
transformmissiletransform.lookat
transform.Lookat problem
Hello
I am making a missile shooting game, and I have run into a issue.
When I fire my missile I want it to look at the direction that the mouse is facing.
I sorta got this to work..... I used transform.LookAt() and what is happening is the missile is spawning side ways...... now sure why. So its semi working. Is there a way to make it spawn with the tip facing where I clicked?
public float timeKeeper = 0;
public float fracDist = .01f;
public Transform boomObj;
void Start ()
{
GameMaster.targetPosition = GameMaster.objPosition;
GetComponent<Transform>().eulerAngles = new Vector3(0, 0, -15);
}
void Update ()
{
timeKeeper += Time.deltaTime;
if(timeKeeper > .04)
{
fracDist += .01f;
timeKeeper = 0;
}
transform.position = Vector2.Lerp(transform.position, GameMaster.targetPosition, fracDist);
transform.LookAt(GameMaster.targetPosition);
}
void OnTriggerEnter(Collider entity)
{
if(entity.gameObject.name == "Crosshair Red(Clone)")
{
Destroy(gameObject);
Instantiate(boomObj, transform.position, boomObj.rotation);
}
}
}
Thanks in advance
Note if I removed Transform.LookAt, then the missile spawns pointing up with no directional change.
Comment
Best Answer
Answer by Shindy117 · Apr 14, 2017 at 05:07 PM
I figured it out. I added
transform.Rotate(new Vector3(90f, 0, 0));
AFTER the transform.lookat function.