• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D EndlessRunner Spike Placing 0 Answers

How to create soil or sand?? 0 Answers

why when change object scale not clicking unity 0 Answers

Game over funcition isn't being called accurately? 2 Answers

A* pathfinding for dynamic obstacles and player made blockages? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges