I’ve definitely seen some scripts and I made mine based on it. But the object just flies left of a player’s facing, not forward at all and then makes random moves.
It is an inventory item I want it to just when thrown to fall down at collision of a wall or other game object.
The inventory item is a game object child of the player, it is seen when player moves and Im not sure if that causes an issue. Here is the script but I need complete remake for the above purpose
So throw and not only moves forward (can be player facing including angle like if player looking down will smash it in the floor)
I will also need to make an event when it collides with certain game object (enemy) the enemy will disappear. Im not sure of the Collision check event.
public class ThrowInventoryItem : MonoBehaviour
{
public GameObject inventoryItemThrown;
public float speed = 5f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetKey("t"))
{
GameObject instantInventoryItemThrown = Instantiate(inventoryItemThrown, transform.position, Quaternion.identity);
Rigidbody inventoryItemThrownRB = instantInventoryItemThrown.GetComponent<Rigidbody>();
inventoryItemThrownRB.AddForce(inventoryItemThrown.transform.position * speed);
Destroy(instantInventoryItemThrown, 5f);
}
}
If you want your Object to be thrown forward, then you have to do: AddForce(player.transform.forward * speed) instead of AddForce(object.transform.position * speed)
– MeistermineAnything else in the lines that has to be remade? Because nothing happens when I press the T even if I replace with AddForce(player.transform.forward * speed) . Previously the object at least went in direction Nvm this did: inventoryItemThrown.GetComponent<Rigidbody>().AddForce(fpViewer.transform.forward * throwForce); Destroy(inventoryItemThrown, 5f);
– Impc7R