Dashing cube forward problem
As the title show I have trouble with dashing my cube a little bit forward on positive x axis using transform.possition. These is my Code:
if (Input.GetKeyDown(KeyCode.LeftControl))
{
transform.position = ???? // I want to go a little bit forward
}
@poria2100, please edit your original post above and provide more information. How far is a "block" ? What does forward mean - on what axis? x, y, or z, and in which direction, positive or negative? When you say you want to "disappear my cube and then appear", you mean you want it to instantly move?
Answer by streeetwalker · Apr 08, 2020 at 06:20 PM
@poria2100, OK, to move an object using transform.position, you can move relative to the current position, or you can move to an absolute position.
To move relative to the current position, the general algorithm is:
current position = current position + a Vector3 that represents the amount you want to move on any of the axes.
A Vector3 is a C# structure defined (x, y, z).
Therefore, if you want to move on positive x, create a 'new Vector3( the positive x value you want to move by, y, z )'. If you don't also want to move by y or z, put zero for those values.
so we can restate the general algorithm:
current position = current position + new Vector3( the x, y, and z values you want to move by )
That should be enough to get you moving!
Follow this Question
Related Questions
Lerping Camera Between Two Points 0 Answers
gameobject position lerp 0 Answers
Need Rect Transform Movement Tips 2 Answers
OnMouseDrag doesn't wokr. 0 Answers
How to preserve Y rotation while setting transform.up? 1 Answer