• 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 Rob4424 · Sep 20, 2013 at 05:13 PM · c#movementcharacterjumpmove

Can't jump in C#

Hello, I have a problem with my character movement script in C#. I can walk, run, the gravity works great, but I can't jump. Here is the code :`using UnityEngine; using System.Collections;

[RequireComponent(typeof(CharacterController))]

[System.Serializable] public class Move { public bool enabled = true; public float walkSpeed = 5.0f; public float runSpeed = 10.0f; public KeyCode runKey = KeyCode.LeftShift; }

[System.Serializable] public class Jump { public bool enabled = true; public float height = 5.0f; public KeyCode jumpKey = KeyCode.Space; }

[System.Serializable] public class Gravity { public bool enabled = true; public float gravityForce = 5.0f; }

public class Controller : MonoBehaviour { public CharacterController characterController;

 private float horizontalAxis;
 private float verticalAxis;

 public Move move;
 public Jump jump;
 public Gravity gravity;

 void Update()
 {
     horizontalAxis = Input.GetAxis("Horizontal");
     verticalAxis = Input.GetAxis("Vertical");

     if(characterController.isGrounded)
     {
         Move(move.enabled, move.walkSpeed, move.runSpeed, move.runKey);
         Jump(jump.enabled, jump.height, jump.jumpKey);
     }
     Gravity(gravity.enabled, gravity.gravityForce);
 }

 public void Move(bool enabled, float walkSpeed, float runSpeed, KeyCode runKey)
 {
     Vector3 moveDirection = new Vector3();
     float speed = 0;

     if(enabled == true)
     {
         moveDirection = new Vector3(horizontalAxis, 0, verticalAxis);
         if(Input.GetKey(runKey))
         {
             speed = runSpeed;
         }
         if(!Input.GetKey(runKey))
         {
             speed = walkSpeed;
         }
         moveDirection *= speed;
         moveDirection = transform.TransformDirection(moveDirection);
         characterController.Move(moveDirection * Time.deltaTime);
     }
 }

 public void Jump(bool enabled, float jumpHeight, KeyCode jumpKey)
 {
     Vector3 moveDirection = new Vector3();

     if (enabled == true)
     {
         if(Input.GetKey(jumpKey))
         {
             moveDirection.y = jumpHeight;
         }
         characterController.Move(moveDirection * Time.deltaTime);
     }
 }

 public void Gravity(bool enabled, float gravityForce)
 {
     Vector3 moveDirection = new Vector3();

     if(enabled == true)
     {
         moveDirection.y -= gravityForce;
         characterController.Move(moveDirection * Time.deltaTime);
     }
 }

}`

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 thadstedman · Nov 23, 2020 at 03:06 PM

Try this video and you don't need any of the player base stuff or the animation stuff that's only for animations And at the top you don't need the using code monkey.Utill or Using V_animation system You only need to watch like the first four minutes or so as well. Here's the link:https: //www.youtube.com/watch?v=ptvK4Fp5vRY&feature=emb_logo

Comment
Add comment · Show 2 · 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
avatar image thadstedman · Nov 23, 2020 at 03:08 PM 0
Share

Oh the link isnt clickable hmm

avatar image thadstedman · Nov 23, 2020 at 03:08 PM 0
Share

Well on YouTube you can look up code monkey jumping tutorial Unity and that Should be it

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

16 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

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

[C#] Jump on slopes 1 Answer

Character motor movement and jump 1 Answer

have 3rd person make a side jump -1 Answers

controller.Move not working correctly 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