Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class mainPlayerScript : MonoBehaviour {
  6.  
  7. // represents the direct velocity of the object;
  8. private Vector3 movement;
  9.  
  10. public float movementForce;
  11.  
  12. // rigid body component
  13. public Rigidbody rg;
  14.  
  15. // FYI FRICTION: friction dosen't work on a sphere, use drag instead on your sphere collider.
  16.  
  17.  
  18. // Use this for initialization
  19. void Start () {
  20. rg = GetComponent<Rigidbody>();
  21. }
  22.  
  23. // Update is called once per frame
  24. void Update () {
  25.  
  26. float moveHorizontal = -Input.GetAxis("Horizontal");
  27. float moveVertical = -Input.GetAxis("Vertical");
  28.  
  29. movement = new Vector3(moveHorizontal, 0, moveVertical) * movementForce;
  30. rg.AddForce(movement);
  31.  
  32. if (Input.GetKeyDown("space"))
  33. {
  34. jump(5);
  35. }
  36. }
  37. void jump(float multiplier)
  38. {
  39. rg.AddForce(new Vector3(0, multiplier * 100, 0));
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement