Error adding force

Using this code in the Update() function I am instantiating an object prefab and then applying a force to it. However, it produces 2 errors, claiming that AddForce is not a part of the Rigidbody class. :frowning:

if (Input.GetButtonDown("Jump"))
	{
		var plasma = Instantiate(plasmaPrefab, GameObject.Find("plasmaSpawnPoint").transform.position, Quaternion.identity);
		
		plasma.rigidbody.AddForce(transform.forward* 200);
		
	}

Here’s a pic of the error and the inspector for the Plasma prefab I’m instantiating.

Thanks for the help!


I ask only just to “open the game”… where did you set plasmaPrefab? maybe you forgot to assign it a prefab.

Here:

var plasmaPrefab : transform;

Little update, I redid everything (created a new plasma prefab and everything) and now its creating and shooting the plasma bullet but is only shooting it in one direction, even when the player angle changes. How do I get the plasma to shoot in the direction the ship is facing?

It sounds like you are shooting in world space, not local space. Transform.forward should fix that but, if not then try using Transform.TransformDirection() with the direction you want.