Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kachupi · Jan 26, 2014 at 05:38 PM · javascriptcharactercontrollerjumpjumping

character controller wont rise when I Jump :(

Good news, I've finally got my jump animation working, bad news is I cant jump over obstacles because my character controller wont move when I jump here's an example, alt text

also if i let go of the directional buttons my character automatically returns to facing forwards whether running or jumping, i'd like to be able to fix that too :)

  #pragma strict
 
 function Start () {
 
 animation["Jump_pose"].layer = 2;
 }
 
 function Update () { 
 
 if (Input.GetButtonDown ("Jump"))
 animation.CrossFade ("Jump_pose");
 }

This is my Jump script, above and my character controller script below.

 #pragma strict
 
 var rotationSpeed : float = 10;
 var walkSpeed : float = 7;
 var gravity : float = 50;
 private var yRot : float;
 var body : Transform;
 
 function Update () {
 
 
 var Controller : CharacterController = GetComponent(CharacterController);
 var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
 var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
 var height : Vector3 = transform.TransformDirection(Vector3.up);
 
 
 if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")){
 
 animation.CrossFade("walk", 0.2);
 
 animation["walk"].speed = walkSpeed/10;
 
 Controller.Move((vertical *(walkSpeed* Input.GetAxis("Vertical"))) *Time.deltaTime);
 
 Controller.Move((horizontal *(walkSpeed* Input.GetAxis("Horizontal"))) *Time.deltaTime);
 }else{
 
 animation.CrossFade("idle", 0.2);
 }
 
 if(Input.GetAxis("Mouse X")){
 
 yRot += 10 * Input.GetAxis("Mouse X");
 }
 Controller.Move(height *-gravity* Time.deltaTime);
 }
 
 function LateUpdate(){
 
 if(Input.GetAxis("Vertical") == 0){
 if(Input.GetAxis("Horizontal") > 0){
 body.localEulerAngles.y = 90;
 }else if(Input.GetAxis("Horizontal") < 0){
 body.localEulerAngles.y = -90;
 }
 }else if(Input.GetAxis("Vertical") > 0){
 if(Input.GetAxis("Horizontal") > 0){
 }else if(Input.GetAxis("Horizontal") < 0){
 }
 }else if(Input.GetAxis("Vertical") < 0){
 if(Input.GetAxis("Horizontal") > 0){
 }else if(Input.GetAxis("Horizontal") < 0){
 }
 }
 } 

hope someone can help! x

jump_issue.jpg (107.0 kB)
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
1

Answer by Kachupi · Feb 13, 2014 at 12:22 PM

never mind i found the problem, i used the script here http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.Move.html and stuck my animation cross fade in it, i also realised i had to take any gravity effecting script off of my character movement script so my separate jump script dealt with all the gravity uses. heres my script now,

pragma strict

 var speed : float = 6.0;
     var jumpSpeed : float = 8.0;
     var gravity : float = 20.0;
 
     private var moveDirection : Vector3 = Vector3.zero;
 
 function Start () {
 
 animation["jump"].layer = 2;
 }
 
 function Update () { 
 var controller : CharacterController = GetComponent(CharacterController);
         if (controller.isGrounded) {
             // We are grounded, so recalculate
             // move direction directly from axes
             moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                     Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= speed;
             
             if (Input.GetButton ("Jump")) {
                 moveDirection.y = jumpSpeed;
                 animation.CrossFade ("jump");
             }
         }
 
         // Apply gravity
         moveDirection.y -= gravity * Time.deltaTime;
         
         // Move the controller
         controller.Move(moveDirection * Time.deltaTime);
     }

also I had to play around with the gravity level in the inspector so it fitted my jump animation, i'm gonna leave this on here for people to find who have had similar issues/problems, hope this helps! x

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

18 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

Related Questions

Jumping not always work 2 Answers

Player sticks to ground occasionally after trying to jump 0 Answers

Problems with jumping script 1 Answer

Unity Character Controller jumps instantly 0 Answers

Detecting CharacterController jumping 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