-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerMovement.cs
More file actions
40 lines (32 loc) · 1.12 KB
/
Copy pathPlayerMovement.cs
File metadata and controls
40 lines (32 loc) · 1.12 KB
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
34
35
36
37
38
39
40
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerMovement : MonoBehaviour
{
//This is a reference to the Rigidbody component called"rb"
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500;
//We marked this as "Fixed"Update because we
//are using it to mass with Physics.
void FixedUpdate()
{
//Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("d"))//if the Player is pressing the "d" key
{
//Add a force tho the right
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("a")) // If the player is pressint the "a" key
{
//Add a force to the left
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if(rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
}