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 kitommy · Sep 11, 2015 at 01:00 PM · c#unity 52d game2d-platformer2d-gameplay

2D game Unity5

i use Unity5

I have an object that I put the scale of it is (0.2,0.2,0.5) and I make my object double jumps. It's work

But when I adjust the size scale is (0.5,0.5,0.5), then it can not double jump. Double Jump not work i Really don't understand . help me this problem

  using UnityEngine;
 using System.Collections;
 
 public class GiantScript : MonoBehaviour
 {
     Animator anim;
     public bool grounded, doubleJump, jumping;
     public Rigidbody2D rid;
     public float jump;
     public GameObject  ground;
     public LayerMask mask;
     // Use this for initialization
     void Start ()
     {
         anim = GetComponent<Animator> ();
     }
     // Update is called once per frame
     void Update ()
     {
 
         grounded = Physics2D.Linecast (transform.position, ground.transform.position, mask);
         if (grounded) {
             jumping = false;
             doubleJump = false;
         }
         if (Input.GetMouseButtonDown (0) && grounded && !doubleJump) {
             jumping = true;
             doubleJump = true;
             rid.velocity = new Vector3 (0, 50 * jump, 0);
         }
         if (Input.GetMouseButtonDown (0) && !grounded && doubleJump) {
             rid.velocity = new Vector3 (0, 60 * jump, 0);
             doubleJump = false;
         }
         anim.SetBool ("GiantRun", grounded);
         anim.SetBool ("GiantJump", jumping);
     }
 
 }
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 Ben-Stoneman · Sep 11, 2015 at 03:41 PM

@kitommy Firstly you should use FixedUpdate() when using physics in update.

I'm not 100% sure if this is the issue but you may want to check if the object is grounded in a different way.

Here is a basic script:

 using UnityEngine;
 using System.Collections;
 
 public class JumpScript : MonoBehaviour
 {
     public float groundDistance;
     Rigidbody rb;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
     void FixedUpdate()
     {
         if (Input.GetButtonDown("Jump"))
         {
             bool isGrounded = GroundedCheck();
             if (isGrounded)
             {
                 rb.velocity = new Vector3(0, 10, 0);
 
             }
             if (!isGrounded)
             {
                 rb.velocity = new Vector3(0, 2, 0);
             }
         }
     }
     public bool GroundedCheck()
     {
         //Checks the distance from the center of the object to the base of the object.
         groundDistance = this.gameObject.GetComponent<BoxCollider>().bounds.extents.y;
         //Creates a raycast to check if the ground is below this object
         return Physics.Raycast(transform.position, -Vector3.up, groundDistance + 0.1f);
     }
 }

GroundCheck() will check if the object is grounded regardless of the size. This should rule out the issue being with the isGrounded check. If this does not fix the issue then it may be due to the jumping and doubleJump booleans.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how to move a puzzle piece from current position to empty position 0 Answers

Unity doesn't open mi project 0 Answers

2D EndlessRunner Spike Placing 0 Answers

HOLD THE JUMP BUTTON TO JUMP HIGHER 0 Answers

2d shooting problem 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