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 /
This question was closed Feb 19, 2015 at 12:43 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Lainex · Feb 19, 2015 at 12:41 AM · rigidbodyaddforcejumping

Questions regarding jumping

I know this is really easy stuff, but I coudn't find a definitive answer, so I thought I should ask. It's an odd combination but I'm trying to learn how to create a basic character controller, by using Brackeys https://www.youtube.com/watch?v=PazLGgeFkHI (translating the code to C#) and the CharacterController2D you can find in the official documentation, only taking the basic concepts to 3D. Now you see, unlike the video ,where the ball actually jumps with the force, my cube just blinks a couple of coordinates up, without all the smoothness. My code should work the same way, even though I'm using rigidbody.addforce instead of velocity, but neither works anyway. I would really like to hear any suggestions. Thanks in advance! My code:

  using UnityEngine;
     using System.Collections;
     
     public class Movement : MonoBehaviour {
     
         private Vector3 movement;
         private float jumpSpeed = 8.0f;
         private bool fallin = false;
         public Vector3 speed = new Vector3(10, 0, 10);
     
         void Update () {
             float inputX = Input.GetAxis ("Horizontal");
             float inputZ = Input.GetAxis ("Vertical");
             movement = new Vector3 (speed.x * inputX, 0, speed.z * inputZ);
             rigidbody.velocity = movement;
     
             if (Input.GetKeyDown(KeyCode.Space) && fallin == false) {
                 rigidbody.AddForce(Vector3.up * jumpSpeed, ForceMode.VelocityChange);
                 fallin = true;
             }
         }
         void OnCollisionStay() {
             fallin = false;
         }
         
     }


Comment
Add comment · Show 2
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 meat5000 ♦ · Feb 18, 2015 at 11:05 PM 0
Share

Have you tried forcemode impulse?

avatar image Lainex · Feb 18, 2015 at 11:40 PM 0
Share

It still just blinks to the coordinate ins$$anonymous$$d of going to it smoothly, like it should.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by meat5000 · Feb 19, 2015 at 12:44 AM

You are zeroing out your jump velocity on the next frame.

Change the line to the following:

 movement = new Vector3 (speed.x * inputX, rigidbody.velocity.y, speed.z * inputZ);

I tried your script and it barely got off the ground. With the new line it was smooth as silk. If this doesn't work there is something wrong which is not contained within that script.

Comment
Add comment · Show 1 · 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 Lainex · Feb 19, 2015 at 08:17 AM 0
Share

Oh yeah, it works now. Thanks a bunch!

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Problem with rigidbody jumping off of platform. 0 Answers

Jumping with rigid body3d 1 Answer

Why is my rigidbody jump height different every time, despite being in FixedUpdate. 1 Answer

Why wont my character jump? (using rigidbody and addForce) 1 Answer

Character Jumping 2 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