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 mainPlayerScript : MonoBehaviour {
- // represents the direct velocity of the object;
- private Vector3 movement;
- public float movementForce;
- // rigid body component
- public Rigidbody rg;
- // FYI FRICTION: friction dosen't work on a sphere, use drag instead on your sphere collider.
- // Use this for initialization
- void Start () {
- rg = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update () {
- float moveHorizontal = -Input.GetAxis("Horizontal");
- float moveVertical = -Input.GetAxis("Vertical");
- movement = new Vector3(moveHorizontal, 0, moveVertical) * movementForce;
- rg.AddForce(movement);
- if (Input.GetKeyDown("space"))
- {
- jump(5);
- }
- }
- void jump(float multiplier)
- {
- rg.AddForce(new Vector3(0, multiplier * 100, 0));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement