Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour
- {
- public float speed = 100f;
- Rigidbody rb;
- Vector3 v, r;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- float x = 0, y = 0, z = 0, j = 0;
- if (Input.GetKey(KeyCode.W))
- {
- z = 1;
- }
- if (Input.GetKey(KeyCode.S))
- {
- z = -1;
- }
- if (Input.GetKey(KeyCode.A))
- {
- y = -1;
- }
- if (Input.GetKey(KeyCode.D))
- {
- y = 1;
- }
- if (Input.GetKey(KeyCode.Space))
- {
- if (transform.position.y < 10)
- {
- j = 1;
- z += 10;
- }
- }
- v = new Vector3(x, j, z) * speed;
- r = new Vector3(0, y, 0) * 200;
- rb.AddRelativeForce(v);
- rb.AddTorque(r);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement