- Home /
Using lookat for a specific direction (not an object)
Say im given the direction of an objects forward (transform.forward) and then an initial position of that transform.
I initiate an object/class "RPG" (as i'm working on the trajectory of an RPG Launcher here), and it takes the parameters of that initial position, the objects forward, and the speed of the grenade (which i do not need to worry about).
How do i make the grenade look in the direction of the initial positions forward using the first two parameters.
Answer by Seth-Bergman · Dec 30, 2012 at 05:28 AM
if you would post your code this would be easier to explain.. But it sounds like all you want is to set the initial rotation of a projectile, to match the launcher, yes? so you should just be able to say:
projectile.transform.rotation = launcher.transform.rotation;
There is no need for lookat in this case
But just for example sake:
projectile.transform.LookAt(launcher.transform.position * launcher.transform.forward * 100);
something like this would do it
Or something fancier, such as rocket.LookAt(rocket.pos+rocket.rigidbody.velocity)
after you set the speed.
To look literally in a direction, cutting out the "pos+," can use rocket.rotation=Quat.LookRotation(player.forward+V3.up*0.5)
.
Hold on. you're multiplying two Vector3 variables? It gives me an error when i do this.
That should be a PLUS after launcher.transform.position
, in the Answer.
But a V3 times a V3 (doing pairwise multiply to give a V3 result) is sometimes useful, and is legal some places, just not in Unity.