Question by
CptHotstepper · Jun 09, 2017 at 03:43 PM ·
movepositiondirections
How to move a cube to any direction in 2D.
Hi,
I'm making a 2D game in which i need to move a cube in various directions. Till now I moved the cube using rigidbody.MovePostion but only in downward direction. Below is the Code,
void FixedUpdate() {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
direction = new Vector2 (moveHorizontal, moveVertical) * speed * Time.deltaTime;
rb.MovePosition (rb.position + direction);
}
I've tried many ways to move it upward, left and right direction but nothing worked.
Can anyone help me in this issue.
Comment
Your answer
Follow this Question
Related Questions
how to stack possible move for minimax algoritm? 0 Answers
MovePosition() at the same time doesn't work 0 Answers
MovePosition/Velocity not following a direction 0 Answers
Kinematic 2D Rigidbody movement: Rigidbody2D.MovePosition vs Rigidbody2D.position problem 1 Answer
Moving a rigidbody in local space with transform.TransformPoint has unexpected results. 1 Answer