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 /
  • Help Room /
avatar image
0
Question by $$anonymous$$ · Oct 11, 2017 at 12:32 PM · rigidbody physicsrigidbody collision

Third Person Controller C#

I need to know where to fix my Jump feature in this script. Here are the basic issues.

  • I cannot add gravity with isGrounded. I don't know how to apply it and tried several ways.

  • When i hold spacebar character turns slightly to the left and continues to climb.

  • If i hold forward movement down while jumping character is locked in jump pose till I stop holding down one of the keys.

  • I would also like to have a double hit option on '/?' key to shift from run or walk but don't know how to do so and stuck using the left ctrl button.

Here is the code; any modifications will be greatly appreciated and please ass a note where the code was added in the same manner as this code has been provided or I will likely mess it up.

 using System;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour
 {
 
     public Animator anim;
     public Rigidbody Rb;
     public float speed;
     private bool run;
     private bool jump;
     public float inputH = 20f;
     public float inputV = 50f;
 
   // Use this for initialization
     void Start()
     {
         anim = GetComponent<Animator>();
         Rb = GetComponent<Rigidbody>();
         inputV = inputH = 0;
         run = false;
         jump = false;
     }
    
     // Update is called once per frame
     void Update()
     {
         inputH = Input.GetAxis("Horizontal");
         inputV = Input.GetAxis("Vertical");
 
         anim.SetFloat("inputH", inputH);
         anim.SetFloat("inputV", inputV);
         anim.SetBool("run", run);
         anim.SetBool("jump", jump);
 
         float moveX = inputH * 20f * Time.deltaTime;
         float moveZ = inputV * 50f * Time.deltaTime;
 
         if (moveZ <= 0f)
         {
             moveX = 0f;
         }
         else if (run)
         {
             moveX *= 6f;
             moveZ *= 6f;
         }
       
         if (Input.GetKey(KeyCode.LeftControl))
         {
             run = true;
         }
         else
         {
             run = false;
         }
         if (Input.GetKey(KeyCode.Space)) 
         {
             jump = true;
         }
         else
         {
             jump = false;
         }
      }
 
    }

I don't know anything about applying any other physics for things like slope detection or walking up and down various stairs or ramps but it seems to be working fine as is aside from the jump and gravity issues, and of course my interest in coding the changing run to walk so i only have to hold down one key. Its intended for a Online PC game.

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

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.

Follow this Question

Answers Answers and Comments

116 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

Related Questions

How to prevent jumping off held object? 0 Answers

Remove Rigidbody2D "Jelly" Collisions? 1 Answer

Rigidbody object glitching upon colliding with static object,Rigidbody object spinning and glitching when colliding with static object 0 Answers

How to create a generic script for bouncing behaviour 1 Answer

Rigidbody 2D Not Working Stable 0 Answers


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