- Home /
Add force seems to add random amount of force?
Hey guys, I've been trying to deal with this for a while now, about 70% of the time, my script works, I'm making a character who can throw the item that they are holding in the direction that they press the control stick, and it works about 80% of the time, and sometimes just adds way too much force onto the object? I can't see any reason why this would be happening.
void Update()
{
if (Input.GetButtonDown(throwButton))
{
if (item[0] != null)
{
Throw(item[0].GetComponent<Item>(), 0); //throw the item in right
}
}
public void Throw(Item weaponToThrow, int index) { weaponToThrow.gameObject.GetComponent().isKinematic = false; weaponToThrow.gameObject.transform.parent = null; throwForce = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); throwForce.Normalize(); float m_Angle = Mathf.Atan2(-throwForce.x, throwForce.y) Mathf.Rad2Deg; weaponToThrow.gameObject.GetComponent().rotation = Quaternion.Euler(0f, 0f, m_Angle); weaponToThrow.gameObject.GetComponent().AddForce(weaponToThrow.transform.up Time.deltaTime * 1000, ForceMode2D.Impulse); weaponToThrow.gameObject.GetComponent().grabbable = true; weaponToThrow.gameObject.GetComponent().enabled = true; item[index] = null; }
Even when pressing no direction on the control stick, the force still seems to be random? Any help would be greatly appreciated. The only guess that I have is it's somehow applying the vector2 throwforce to the throw, but I'm not sure if that's happening...
Answer by gridGuy · May 24, 2020 at 06:50 PM
Solved it, simply get rid of the "time.deltatime" in the equation, it varies per frame and greatly changes the amount of force applied to an object..... my entire game is saved...