Question by
1234filip · Oct 05, 2015 at 12:33 PM ·
2dbutton2d-platformerrigidbody2d2d-physics
How Do I make my character move?
So I have a button which is suposed to when held move character right. So here's the code
var tr : Transform;
var rb : Rigidbody2D;
var right = true;
var left = true;
function Start() {
}
function FixedUpdate () {
tr.transform.Rotate(0, 0, -1);
}
function buttonUpr(){
if(right == false){
rb.AddForce(Vector2(-300, 0));
}
right = true;
}
function buttonDownr(){
if(right == true){
rb.AddForce(Vector2(300, 0));
}
right = false;
}
And i bind ButtonDownr to event trigger pointer down and ButtonUpr to pointer up plz help (the script is bound to the ball)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612040113im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I slow the movement of a single rigidbody2D? 2 Answers
How to move rigidbodies with 2D Character controller (No rigidbody) 1 Answer
Walking around 2D planets? 1 Answer
Best ground 2D ground check strategy? How to detect if a object is touching the top of a layer? 0 Answers
Circle Collider2D Stuck ob Box Collider2D at the corner :( 0 Answers