![]() You can try to make sense of this by visualizing how a sprite rotates in a normal 2D game, or an image editor program like paint.NET, how it is always facing the screen. If you don't want object to fly up when its transform is looking into the sky, do this: float x Input.GetAxis('Horizontal') float z Input.GetAxis('Vertical') Vector3 forward transform.forward //here, make Y component of the vector 0, thus only using it for direction on the flat plane. We use Vector3.forward here because in standard Unity2D setup, the forward vector points into the screen. Just use transform., you get a vector that is pointing relative to the object. The tutorial made a right-and-left control of the player ship, but I changed it to rotational control (which took a while because for some reason almost no script correctly confined the rotation to the boundaries I've set). Is there a best, simple place to learn this. This will rotate angle degrees around the supplied vector. I've used a simple Unity tutorial to make a Space Invaders game, but I want to adapt it into a different game. I want to figure out how to do this hypothetically, without needing to instantiate objects with Transform components. ![]() How would I do this? Normally with a GameObject you can just use Transform.Translate(), or Transform.Right, but that means you need to have an existing GameObject in the scene to calculate it. From here though, say I wanted to move 3 units along to the right, from the facing direction of A to B. Edit : the way I've calculated the forward of the object is like so : Forward.X Object.x+'distance multiplier'sin (object.rotation Z) Forward.Y Object.y+'distance multiplier'cos (object.rotation Z) Why I needed it in the form of (1,0,0) is so I could place another object behind it that is always facing the initial object's back by. ![]() Depending on how you have your app setup, you will likely need either transform.up or transform. For a 2D object, transform.forward will be into the screen and therefore not have any meaning to a rigidbody2D.AddForce() call. Its possible to move an object relative to the position of the camera in Unity by using the cameras forward vector in place of the objects forward. The facing direction would be x=10, y=23. transform.forward A 2D object moves on the XY plane. To get the facing direction of A to B you'd just do (Object B - Object A = (20 - 10) (43 - 23)). Forward will always be the Z vector of the object after rotations have. TLDR version: Input Systems Composite Vector2 does not allow combined (diagonal) movement, only separate forward-backwards and left -right for some reason. So in other words, say I had object A in position (x=10, y=23), and object B in position (x=20, y=43). Forward using global forward instead of local.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |