Search Unity

Broken Rigidbody Physics

Discussion in 'Physics' started by r100pogo, Feb 9, 2019.

  1. r100pogo

    r100pogo

    Joined:
    Feb 9, 2019
    Posts:
    1
    Hello,

    The video will explain everything about what's broken.



    --playerMovementScript.cs
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class playerMovementScript : MonoBehaviour
    7. {
    8.  
    9.     public float moveSpeed;
    10.     public float jumpForce;
    11.     public Vector2 mouseSenstivity = new Vector2(10, 10);
    12.     public Rigidbody rb;
    13.     public Transform cameraChild;
    14.     private bool jumpBug = true;
    15.  
    16.     private void OnCollisionEnter(Collision col)
    17.     {
    18.         if(col.collider.tag != "Player")
    19.         {
    20.             jumpBug = true;
    21.         }
    22.     }
    23.  
    24.     private void Update()
    25.     {
    26.         transform.Translate(moveSpeed*Input.GetAxis("Horizontal Movement")*Time.deltaTime, 0f, moveSpeed*Input.GetAxis("Vertical Movement") * Time.deltaTime);
    27.         transform.Rotate(0f, mouseSenstivity.x*Input.GetAxis("Mouse X")*Time.deltaTime, 0f);
    28.         cameraChild.Rotate(mouseSenstivity.y*(-Input.GetAxis("Mouse Y"))*Time.deltaTime, 0f, 0f);
    29.     }
    30.  
    31.     private void FixedUpdate()
    32.     {
    33.         if (Input.GetAxis("Jump") > 0 && jumpBug)
    34.         {
    35.             rb.AddForce(0f, jumpForce, 0f);
    36.             jumpBug = false;
    37.         }
    38.     }
    39. }
    40.  
     
  2. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    452
    I've copied as much as I could from your video and I'm not seeing the problem. Try to create a new project and create objects step by step verifying that everything is working. This way when it breaks you'll know what caused it. This is a good workflow for any project you will be working on. Try disabling your script to see if that is causing it. Almost looks like your ground collider centre is offset but it shows correct in the video. If still struggling post the project and I'll have a look.

    Check your gravity setting. I think you might have cranked it up too high. Edit->ProjectSettings->Physics. If you want to have a strong gravity and not go though the floor I think you will have to assign physics materials to your colliders. Assets->Create->PhysicMaterial
     
    Last edited: Feb 11, 2019