- Home /
transform.forward?
Is there a way to find the way an object is facing? I need my character to spawn like 0.3 units away from the object in the direction the object is facing (it is a 2D object). I tried transform.forward, but that does not seem to work... Is there a way to get the relative direction of a face?
Answer by Mike 3 · Mar 11, 2011 at 07:15 PM
transform.forward should work fine
Assuming your code looks something like this, there shouldn't be an issue:
Instantiate(prefab, transform.position + transform.forward * 0.3, transform.rotation);
Actually, I'm just redefining the player's transform...
Should still work at any rate - could you post the code you're trying?
Answer by Statement · Mar 11, 2011 at 07:21 PM
Given it's a 2d object, maybe your forward vector (blue axis) points out of the screen and into the camera? If so, you could try transform.right, (red axis), which would place the object on the right side of the 2d object.
Answer by PrimeDerektive · Mar 11, 2011 at 07:14 PM
var offset : float = 0.3;
var spawnPosition : Vector3 = new Vector3(transform.x, transform.y, transform.z+offset);
There isn't a transform.x/y/z, nor would adding a value onto the world z position work with a rotated object
Your answer
Follow this Question
Related Questions
Make simple moving platform 2 Answers
Declaring variables in Update(). 2 Answers
Simple object rotation & LookAt 1 Answer
simple movement help 1 Answer