Search Unity

Ragdoll and movement

Discussion in 'Scripting' started by S3Critsss, Jan 21, 2020.

  1. S3Critsss

    S3Critsss

    Joined:
    Jan 6, 2020
    Posts:
    111
    I made my player a ragdoll but when i added my script the ragdoll stopped working so i added to ignore the colliders but it still wont work
    this is the code
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class movePlayer : MonoBehaviour
    7. {
    8.     public Transform groundCheckPoint;
    9.     public float groundCheckRadius;
    10.     public LayerMask groundLayer;
    11.     public GameObject Player;
    12.     public float speed;
    13.     public float jumpHeight;
    14.     private float move;
    15.     private Rigidbody2D rb;
    16.     private bool isGrounded;
    17.  
    18.     void Start()
    19.     {
    20.         rb = GetComponentInChildren<Rigidbody2D>();
    21.  
    22.         Collider2D[] colliders = Player.GetComponentsInChildren<Collider2D>();
    23.         for (int i = 0; i < colliders.Length; i++)
    24.         {
    25.             for (int k = i + 1; k < colliders.Length; k++)
    26.             {
    27.                 Physics2D.IgnoreCollision(colliders[i], colliders[k]);
    28.             }
    29.         }
    30.     }
    31.  
    32.     void Update()
    33.     {
    34.         isGrounded = Physics2D.OverlapCircle(groundCheckPoint.position, groundCheckRadius, groundLayer);
    35.  
    36.         move = Input.GetAxis("Horizontal");
    37.  
    38.         rb.velocity = new Vector2(move * speed, rb.velocity.y);
    39.  
    40.         if (Input.GetButtonDown("Jump") && isGrounded)
    41.         {
    42.             rb.AddForce(new Vector2(rb.velocity.x, jumpHeight));
    43.         }
    44.  
    45.         if (Input.GetKeyDown(KeyCode.LeftShift))
    46.         {
    47.             speed = 15f;
    48.         }else if (Input.GetKeyUp(KeyCode.LeftShift))
    49.         {
    50.             speed = 10f;
    51.         }
    52.     }
    53. }
    54.  
    55.  
    ant his is the heirarchy
    1.png