Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

AddForce Jump Doesn't Work

$
0
0
Hello , I don't know why Jump don't work // im new in unity so i need some help Note : walk is good!! using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { CharacterController controller; private Rigidbody rb; private Animator playeranim; public float speed = 18.0f; public float gravity = -12f; public float jump = 15f; private float verticalVelocity; public bool IsOnGround = true; Vector3 movedirection = Vector3.zero; // Start is called before the first frame update void Start() { rb = GetComponent(); playeranim = GetComponent(); controller = GetComponent(); } // Update is called once per frame void Update() { Jump(); walk(); } void walk() { float leftrightzft = Input.GetAxis("Horizontal") * 3f; if (IsOnGround == true) { movedirection = new Vector3(leftrightzft, 0, 2f); movedirection *= speed; } controller.Move(movedirection * Time.deltaTime); } void Jump() { if (IsOnGround&&Input.GetKeyDown(KeyCode.Space)) { rb.AddForce(Vector3.up * jump, ForceMode.Impulse); } } private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Ground")) { IsOnGround = true; } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>