- Home /
How to detect what layer is colliding
I am trying to add jumping to the player. I want to know how to detect what layer the player is colliding with to determine when to allow the player to jump. Here is my code. I got a ton of errors in the console and I looked at others trying to do the same but the solutions did not work.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movement : MonoBehaviour { public float speed = 20f; public Transform player; public bool isGrounded = true; public Rigidbody rigidbody; public float jump = 1000f; public LayerMask Ground; void FixedUpdate() { float y = Input.GetAxis("Vertical") * speed * Time.deltaTime; float x = Input.GetAxis("Horizontal") * speed * Time.deltaTime; function OnCollisionEnter(collision : Collision) { if (collision.collider.gameObject.layer == LayerMask.NameToLayer("Ground")) ; { isGrounded = true; } } if(Input.GetKey("space") && isGrounded == true) { rigidbody.AddForce(0, jump * Time.deltaTime, 0); } player.Translate(Vector3.forward * y); player.Translate(Vector3.right * x); } }