• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Promas1234 · 4 days ago · errorinput

unity doesn't detect space for me sometimes randomly

when I'm testing the first person character and I want to jump if I don't move the camera or I don't move it just doesn't jump

using System.Collections; using System.Collections.Generic; using UnityEngine;

//Requeriments [RequireComponent(typeof(Rigidbody))]

public class PlayerController : MonoBehaviour { // //Variables //

 //Components
 Rigidbody rb;

 //Movement
 [Header("Movement")]
 [SerializeField] float speed;

 Vector3 movePlayer;
 Vector3 rightCamera;
 Vector3 forwardCamera;

 //Look
 [Header("Look")]
 [SerializeField] Transform camTransform;
 [SerializeField] float MaxAngleVertical;

 float verticalLook;
 float horizontalLook;

 //Jump
 [Header("Jump")]
 [SerializeField] float jumpForce;
 [SerializeField] LayerMask jumpLayer;

 //-----------------------------------------------------

 // Start is called before the first frame update
 void Start()
 {
     //Initialize:
     rb = GetComponent<Rigidbody>();

     Debug.Log("Player Generated");
 }

 // Update is called once per frame
 void Update()
 {
     Look();
     Movement();
     Jump();

     rb.velocity = movePlayer;
 }

 //
 //Movement
 //
 void Movement()
 {
     //
     //Get Keyboard Input
     //

     Vector2 keyboardInput = InputManager.Instance.GetKeyboardAxis();

     //
     //Get Camera Angles
     //

     rightCamera = camTransform.right;
     rightCamera.y = 0;
     rightCamera = rightCamera.normalized;

     forwardCamera = camTransform.forward;
     forwardCamera.y = 0;
     forwardCamera = forwardCamera.normalized;

     //
     //Move
     //

     movePlayer = keyboardInput.x * rightCamera + keyboardInput.y * forwardCamera;
     movePlayer *= speed;

     //Gravity

     movePlayer.y = rb.velocity.y;

     
 }

 //
 //Look
 //
 void Look()
 {
     //
     //Get Mouse Input
     //

     Vector2 mouseInput = InputManager.Instance.GetMouseAxis();

     //
     //Look
     //

     //Vertical Look

     verticalLook -= mouseInput.y;
     verticalLook = Mathf.Clamp(verticalLook, -MaxAngleVertical, MaxAngleVertical);
     camTransform.rotation = Quaternion.Euler(verticalLook, camTransform.rotation.eulerAngles.y, 0);

     //Horizontal Look

     horizontalLook += mouseInput.x;
     transform.rotation = Quaternion.Euler(0, horizontalLook, 0);
 }

 //
 //Jump
 //
 void Jump()
 {
     if (!IsGrounded().transform) return;

     Debug.Log("Grounded");

     if (!InputManager.Instance.PressJump()) return;

     Debug.Log("Jump");
     movePlayer.y = jumpForce;
 }


 /// <summary>
 /// Is true if player is in touching ground
 /// </summary>
 /// <returns></returns>
 public RaycastHit IsGrounded()
 {
     Ray r = new Ray(transform.position, -transform.up * 1.3f);
     RaycastHit hit;
     Debug.DrawRay(transform.position, -transform.up * 1.3f);
     Physics.Raycast(r, out hit, jumpLayer);
     return hit;
 }

}

Comment

People who like this

0 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MUG806 · 3 days ago 0
Share

Please clearly explain:

  • what you are trying to do

  • what you expect to happen

  • what happens instead

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

226 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

'GetAxis' is not a member of 'function(): void' 1 Answer

Failed to get cursor position: Access is denied. 1 Answer

MicInput Conversion to C# 0 Answers

Problems with Input.acceleration in Unity 4.1 1 Answer

error CS0117: `Input' does not contain a definition for `GetKeyDown' 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges