Feedback on Throw object logic

Hey guys!,
I have a question about throwing objects.

I’m working on a small game where the player has a dice floating around the character, and I am hoping for some feedback on my throw logic. I want to mention that while this feels okay, it’s not 100% consistent. For example, sometimes the dice object is thrown down really hard, barely moving forward.

Any feedback would be greatly appreciated!

private void GetAttackInput()
    {
        // We calculate and cache the direction 
        Vector3 attackDirection = player.forward;
        Vector3 playerVelocity = player.GetComponent<Rigidbody>().velocity;

        // We get input from the player
        if(Input.GetKeyDown("mouse 0") && !isAttacking)
        {
            isAttacking = true;
            rb.useGravity = true; // We enable gravity when attacking to make it arc down as it travels

            rb.AddForce(attackDirection * attackForce + playerVelocity, ForceMode.Impulse);
        }                                                   
    }
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private float _horizontalInput;
    private float _verticalInput;
    [SerializeField] static float _speed = 20.0f;
    private Rigidbody _rb;
    private Vector3 _moveDir;


    // Start is called before the first frame update
    void Start()
    {
        _rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        // We get player input
        _horizontalInput = Input.GetAxisRaw("Horizontal");
        _verticalInput = Input.GetAxisRaw("Vertical");

        Debug.Log(_rb.velocity);
    }

    private void FixedUpdate()
    {
        // Normalize the magnitude of vectors so diagonal movement is the correct speed
        _moveDir = new Vector3(_horizontalInput, 0, _verticalInput).normalized;
        _rb.velocity = _moveDir * _speed;

        // Prevent player rotation from resetting when player stops moving
        bool isMoving = _moveDir == Vector3.zero ? true : false;
        if(!isMoving) {
            // We rotate the player by setting look rotation to the same vector as our movement direction
            transform.rotation = Quaternion.LookRotation(_moveDir);
        }
    }

    // Allow getting the value of speed without changing its value so its protected
    public static float getSpeed() {
        return _speed;
    }
}

Hello @Jumpman25th. It’s kinda hard to read your code, so could you format it in the site using the </> icon?
Formatting Reference-Unity Discussions
Thank you.

@Jumpman25th, thanks for formatting your code. Now, I am no expert at Unity, especially when it comes to physics, but your code looks pretty good.

As for this, try adjusting the mass of the dice in the inspector, that might help.
But then again, I don’t have much experience when it comes to physics.
Somebody more knowledgeable about the subject will come along soon. :wink: