Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by NSVEnvy · Jan 19, 2019 at 01:50 AM · gameobjectinputplayerplatformerissue

Input doesn't register, but player still moves...

For some reason, the input system on a multiplayer 3d platformer I am making is not working. I looked at other solutions, but none of them worked. I used degub.log to try to see if the input is going through, but it is not registering. However, the player gameObject still reacts to keyboard input. It moves around like it is supposed to, but the jumping does not work and none of the Debug.log lines are being run, leading me to believe that the code is not receiving input... My code for the player is posted below

 using UnityEngine;
 using UnityEngine.Networking;
 //using UnityEngine.SceneManagement;  <--not used yet

 public class LANPlayerMovement : NetworkBehaviour {
 
     public Rigidbody rb;
     public Camera cam;
     public GameObject sceneCam;
 
     public float speed = 10f;
     public float jumpHeight = 7f;
     public float jumpReductionFactor = 1.5f;
     public float jumpTimeDelay = 0.3f;
     public float currentHeight;
     public int maxJumps = 2;
     public int maxHealth = 10;
 
     private int numJumps = 0;
     private int attempts = 0;
     private int currentHealth = 10;
     private float currentJumpHeight;
     private float currentJumpTime = 0f;
     private float deathLevel = 5f;
 
     private Vector3 startPosition;
     private Vector3 startVelocity;
     private NetworkStartPosition spawnPoint;
 
 
     // Called at the beginning of program
     private void Start()
     {
         if (isLocalPlayer) {
             spawnPoint = FindObjectOfType<NetworkStartPosition>();
             cam.GetComponent<Camera>().enabled = true;
         } else {
             cam.GetComponent<Camera>().enabled = false;
         }
 
         startVelocity = new Vector3(0, 0, 0);
     }
 
 
     // Called by other scripts to damage the player
     public void TakeDamage(int dmgAmount)
     {
         if (isLocalPlayer) {
             currentHealth -= dmgAmount;
             CheckDie();
         }
     }
 
 
     // Update is called once per frame
     void Update () {
 
         if (isLocalPlayer) {
             if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetAxisRaw("Horizontal") == 1f)
             {
                 Debug.Log("Right pressed!");
                 rb.AddForce(Vector3.right * speed, ForceMode.Acceleration);
             }
 
             if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetAxisRaw("Horizontal") == -1f)
             {
                 Debug.Log("Left pressed!");
                 rb.AddForce(Vector3.left * speed, ForceMode.Acceleration);
             }
 
             if ((Input.GetKeyDown(KeyCode.UpArrow) || Input.GetAxisRaw("Vertical") == 1f) && numJumps < maxJumps && (Time.time - currentJumpTime) > jumpTimeDelay)
             {
                 Debug.Log("Jump pressed!");
                 rb.AddForce(Vector3.up * currentJumpHeight, ForceMode.Impulse);
                 numJumps++;
                 currentJumpHeight = currentJumpHeight / jumpReductionFactor;
                 currentJumpTime = Time.time;
             }
 
             CheckDie();
         }
     }
 
 
     // Called when collision occurs
     private void OnCollisionEnter(Collision col)
     {
         if (isLocalPlayer)
         {
             currentHeight = transform.position.y;
 
             if (col.gameObject.tag == "floor")
             {
                 numJumps = 0;
                 currentJumpHeight = jumpHeight;
             }
 
             else if (col.gameObject.tag == "damage")
             {
                 TakeDamage(1);
             }
 
             else if (col.gameObject.tag == "kill")
             {
                 TakeDamage(currentHealth);
             }
 
             else if (col.gameObject.tag == "getTime")
             {
                 PlayerPrefs.SetFloat("finishTime", Time.timeSinceLevelLoad);
             }
         }
     }
 
 
     // Check if the death conditions are met
     private void CheckDie()
     {
         if (isLocalPlayer)
         {
             if (transform.position.y < deathLevel)
             {
                 Die();
             }
 
             else if (currentHealth <= 0)
             {
                 Die();
             }
         }
     }
 
 
     // Kills player
     private void Die()
     {
         if (isLocalPlayer)
         {
             currentHealth = maxHealth;
             rb.velocity = startVelocity;
             //transform.position = startPosition;
             transform.position = spawnPoint.transform.position;
             attempts++;
         }
     }
 
 }
 

Any idea on how to fix this?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ray2yar · Jan 21, 2019 at 02:15 PM

You never assign currentJumpHeight, so it stays at 0.

Also, your debugs for clients won't show on the console.

Good luck.

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

170 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

Related Questions

material.SetTexture reset 1 Answer

How to get GameObject that is clicked by a mouse? 2 Answers

Player only spawns upon play 1 Answer

Player Material Change works on shop preview menu, does not change Player material on other scenes. 0 Answers

Input loss. One out of every five or six mouse clicks or button presses don't register. 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