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 RobyRothen · Sep 16, 2014 at 08:30 PM · rotationjumptransform.positionrigidbody.velocitygrounded

Problem with rotation and groundchek _ 2D - C#

Hi everybody, I searched a lot but I didn't find a solution to my problems.

I have a sphere. I want that this sphere jumps after "x" seconds of a timer. I did it but I have 2 problems.

First problem: Trying to understand which is the relation from "second" to "distance" (i.e. after how many seconds the sphere covers 4x unit??) I did a few attempts:

  1. rigidbody.velocity = new Vector3 (2,0,0);

    The sphere rotates BUT the gravity doesn't work and the jump is not natural.

  2. transform.position += Vector3.right speed Time.deltaTime;

    The gravity and the jump are perfect BUT the sphere instead of rotating, crawls.

Second problem:

About the "groundcheck", I wrote this code:

 public bool isJumping = false;
     
     
 
     void FixedUpdate () 
     {

         //stuff
         
         
         if(myCondition)
         {
             
             
             //rigidbody.velocity = new Vector3 (2,0,0);
             //transform.position += Vector3.right * speed * Time.deltaTime; 
             
                  
                 if (myCondition && isJumping == false)
                 {
                     rigidbody.velocity = new Vector3 (0,5,0); //
                     isJumping = true;
                             
                 }
   
         }
         
   }
 
     void OnCollisionEnter(Collision col)
     {
         if(col.gameObject.tag == "Ground")
         {
             isJumping = false;
         }
     }
 }
 

What happens is this:

IF #1: The sphere jumps and then, in the air, tries to jump again -> doesn't jump (perfect!)

IF #2: The sphere is falling, tries to jump -> jump . . . How can I fix this?

I already sat the tag "Ground" to my ground.

I hope you understand my problems (despite my english) and somebody are able to tell me the solutions.

thanks, bye.

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 EvilTak · Sep 17, 2014 at 01:05 AM 0
Share

Ins$$anonymous$$d of modyfing velocity directly, you might want to use rigidbody.AddForce or AddForceAtPoint. That will take care of your first problem.

avatar image RobyRothen · Sep 17, 2014 at 03:53 PM 0
Share

If I use rigidbody.AddForce I can't know after how many seconds my sphere covers #x units. $$anonymous$$y "0" problem is that I need to know where my sphere, in each seconds, will be in the x axis.

With rigidbody.AddForce the speed is not constant . . .

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiwasi · Sep 17, 2014 at 02:05 AM

Not sure exactly what your first problem is. Typically you create a jump by adding a force straight up. Unity takes care of the rest automatically.

For the second problem consider setting isJumping to true in OnCollisionExit, instead of as part of your jump.

Edit: Convention tends to be to use isGrounded instead of isJumping. isGrounded is a more accurate name for situations where the character is not actually jumping, but still cannot jump. Like falling or on a soft/liquid surface.

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 RobyRothen · Sep 17, 2014 at 06:14 AM 0
Share

First problem is about the movement to right, not a jump. If I use the rigidbody.velocity the sphere go to the right doing a 360° movement on the floor (but the jump is not natural and the gravity doesn't work). If, ins$$anonymous$$d, I use transform.position the gravity works but the sphere goes to the right without rotation, as I check "freeze rotation".

For the second problem, I'm new in the use of unity and C# so if you have the "right" code I can correct (and understand) what you mean with "OnCollisionExit". PS: I need to set also as a part of the jump to avoid the "double jump"

Thx

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Issue finding an angle with trigonometry 1 Answer

How to make the missile behave realistic by looking on the direction it is moving? 2 Answers

i want to get my to cube to rotate 90 degrees on the x-axis as it jumps 0 Answers

how do I script this jump animation? 1 Answer

Let Character Controller jump. 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