- Home /
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;
}
}
}
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"))
I could figure it out with applying the same growth of the character to the check radius. thanks for your answer anyway ^^