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 TheWaves · Oct 07, 2016 at 03:26 PM · c#jumpbeginner

Character Won't Jump

Hi. I'm a complete beginner to Unity3D, C# and programming, so I'm using this video as guidance. https://www.youtube.com/watch?v=QvbZYKcpjkY . My only problem is that his character is jumping, while mine is not. Our scripts are identical so I don't know what's wrong. Can anyone help?

 using UnityEngine;
 using System.Collections;
 
 public class SimpleCharacter : MonoBehaviour
 {
 
 
     public CharacterController MyController;
     // Update is called once per frame
     public float Speed = 3f;
     public float GravityStrenght = 5f;
     public float JumpSpeed = 10f;
     public Transform CameraTransform;
 
     void Update ()
     {
         Vector3 myVector = new Vector3(0,0,0);
 
         //get input from the player
         myVector.x = Input.GetAxis("Horizontal");
         myVector.z = Input.GetAxis("Vertical");
         myVector = myVector * Speed*Time.deltaTime;
 
         myVector = CameraTransform.rotation * myVector; //rotate input by direction of camera
 
         //how do we get the jump button?
         float verticalVelocity = MyController.velocity.y - GravityStrenght*Time.deltaTime;
         if (Input.GetButtonDown("Jump")) 
         {
             //add jumpspeed to vertical velocity
             verticalVelocity +=JumpSpeed;
         }
         myVector.y = verticalVelocity*Time.deltaTime; //add new speed, to old speed, for acceleration
         //use input to move the character
         MyController.Move(myVector);
     }
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

Answer by TheWaves · Oct 07, 2016 at 10:03 PM

So, the original script I had magically worked the next time i opened unity. Weird, but I'm glad! Thank you @IceEnry_lol for a suggestion :D

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
avatar image
0

Answer by IceEnry__lol · Oct 07, 2016 at 04:56 PM

I tried to see the script, but I'm not very good with unity because I'm quite new too, so try this :D https://docs.unity3d.com/ScriptReference/CharacterController.Move.html ( you need to attach to your player the character controller) anyway the script is this (it's the same from the Unity scriptreference)

using UnityEngine; using System.Collections;

public class SimpleCharacter : MonoBehaviour { //Variables public float speed = 6.0F; public float jumpSpeed = 8.0F; public float gravity = 20.0F; private Vector2 moveDirection = Vector2.zero;

 void Update() {
     CharacterController controller = GetComponent<CharacterController>();
     // is the controller on the ground?
     if (controller.isGrounded) {
         //Feed moveDirection with input.
         moveDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
         moveDirection = transform.TransformDirection(moveDirection);
         //Multiply it by speed.
         moveDirection *= speed;
         //Jumping
         if (Input.GetButton("Jump"))
             moveDirection.y = jumpSpeed;

     }
     //Applying gravity to the controller
     moveDirection.y -= gravity * Time.deltaTime;
     //Making the character move
     controller.Move(moveDirection * Time.deltaTime);
 }

}

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 TheWaves · Oct 07, 2016 at 08:31 PM 0
Share

Thank you! I will experiment and try it out!

avatar image IceEnry__lol TheWaves · Oct 09, 2016 at 07:44 AM 0
Share

you're welcome :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

My jumping script isn't working, And it isn't giving me any errors,My character isn't jumping, But I don't get any errors 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

I made Infinite jump Fix Script By Myself But I Want You Guys To Take Look at My Script... 0 Answers

Jump/grounding bugs, advice appreciated 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