-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovement Scripts.txt
More file actions
33 lines (30 loc) · 996 Bytes
/
Movement Scripts.txt
File metadata and controls
33 lines (30 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
private Rigidbody2D rbody;
// Start is called before the first frame update
private void Start()
{
rbody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
private void Update()
{
/*
* //it's hardcoded
if (Input.GetKeyDown("w"))
{
rbody.velocity = new Vector3(0, 7, 0);
Debug.Log("Jump started");
}
*/
// It's work on unity input Manager
float moveX = Input.GetAxisRaw("Horizontal"); //if we don't want to slide so then we use raw
rbody.velocity = new Vector2(moveX * 5f, rbody.velocity.y);
if (Input.GetButtonDown("Jump"))
{
/*
replace the zero from rbody.velocity.x
rbody.velocity = new Vector2(0, 7f);
*/
rbody.velocity = new Vector2(rbody.velocity.x, 7f);
Debug.Log("Jump started");
}
}