• 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 jkf- · Jan 17, 2019 at 08:06 PM · 2d-platformerscaleground detection

How do I set Ground Check to a size-changing character?

Hi there

So I'm working on my first Game, in which you play a spherical character. Everything's working fine with the double jump scripting, but my character will be changing it's size throughout the game. So whenever the size increases or decreases, the check radius won't take over the size of the character. Does anyone know a way to put the local scale and check radius in an equation or to use the circle collider of my character as ground check, with the double jump function still working?

(sorry i haven't got much experience yet...)

.

thanks for an answer :)

.

public class Movement : MonoBehaviour {

     public Rigidbody2D rb;
 
     public float jumpForce;
 
     private bool isGrounded;
     public Transform GroundCheck;
     public float CheckRadius;
     public LayerMask WhatIsGround;
     private int extraJumps;
     public int extraJumpValue;
 
     
     
     void Start () {
 
         extraJumps = extraJumpValue;
         rb = GetComponent<Rigidbody2D>();
     
 
     }
 
     // Update is called once per frame
     private void FixedUpdate()
     {
         isGrounded = Physics2D.OverlapCircle(GroundCheck.position, CheckRadius, WhatIsGround);
     }
 
 
     private void Update()
     {
 
         if(isGrounded == true)
         {
             extraJumps = extraJumpValue;
         }
 
 
         if(Input.GetMouseButtonDown(0) && extraJumps > 0)
         {
             rb.velocity = Vector2.up * jumpForce;
             extraJumps--;
         } else if(Input.GetMouseButtonDown(0) && extraJumps == 0 && isGrounded == true)
         {
             rb.velocity = Vector2.up * jumpForce;
         }
     }
 
 }
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 mansoor090 · Jan 18, 2019 at 12:07 PM

@jkf- change the CheckRadius or use a Raycast instead and make an empty gameobject which stays at a certain position (you can make child of your player)

  bool grounded = Physics.Raycast (pivotPos, Quaternion.AngleAxis (90, transform.right) * transform.forward, out hit, 1f **(length of raycast)**, 1 << LayerMask.NameToLayer ("Ground"))




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 jkf- · Jan 23, 2019 at 06:45 PM 0
Share

I could figure it out with applying the same growth of the character to the check radius. thanks for your answer anyway ^^

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

107 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 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 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 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 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 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

2d character flipping and conditionally walking backwards 0 Answers

Flipping Error! Spritesheet and JS! 0 Answers

No response from raycast 0 Answers

Check if circle player is on the ground 4 Answers

[2D] Check if player is on the ground 4 Answers

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