Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Playermovement : MonoBehaviour
- {
- public Rigidbody rb;
- void Start ()
- }
- void Update()
- {
- bool player_jump = Input.GetButtonDown("DefaultJump");
- if (player_jump)
- {
- rb.AddForce(Vector3.up * 365f);
- }
- }
- }
- }
- private Rigidbody rb;
- bool isGrounded = true;
- public float jumpForce = 20f;
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- private void Update()
- {
- bool player_jump = Input.GetButtonDown("DefaultJump");
- if (player_jump && isGrounded)
- {
- rb.AddForce(Vector3.up * jumpForce);
- }
- }
- void OnCollisionEnter(Collision collision)
- {
- if (collision.gameObject.CompareTag("Ground"))
- {
- isGrounded = true;
- }
- }
- void OnCollisionExit(Collision collision)
- {
- if (collision.gameObject.CompareTag("Ground"))
- {
- isGrounded = false;
- }
- }
- private Rigidbody rb;
- public float jumpForce = 20f;
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- private void Update()
- {
- bool player_jump = Input.GetButtonDown("DefaultJump");
- if (player_jump && IsGrounded())
- {
- rb.AddForce(Vector3.up * jumpForce);
- }
- }
- bool IsGrounded()
- {
- RaycastHit hit;
- float raycastDistance = 10;
- //Raycast to to the floor objects only
- int mask = 1 << LayerMask.NameToLayer("Ground");
- //Raycast downwards
- if (Physics.Raycast(transform.position, Vector3.down, out hit,
- raycastDistance, mask))
- {
- return true;
- }
- return false;
- }
Add Comment
Please, Sign In to add comment