Shooter script help, compiler errors C#

Hi all,

I’m trying to use a shooter script for an auto scrolling platform game. I’ve used this particular script before in a different game and it worked fine there but here it is giving me some errors.

Here is the code:

public Rigidbody bullet;
	public float Power = 15f;
	public float MoveSpeed = 2f;
	
	void  Update ()
	{			
		if (Input.GetButtonDown("Fire1"))
		{
			Rigidbody newBullet = Instantiate (bullet, transform.position, transform.rotation) as Rigidbody;
			
			fwd = transform.TransformDirection(Vector3.forward);
			newBullet.AddForce(fwd * power);

However now I am getting the following errors-

Any suggestions?

Your variable, fwd, isn’t defined anywhere, even though you’re assigning it a value on line 11.

Try changing line 11 to:

Vector3 fwd = transform.TransformDirection(Vector3.forward);

Thanks Kortekk, compiler errors are gone :slight_smile:

My bullet however is instantiating and falling behind my player (who has an autoscroll script attached). I have tried adjusting power and speed without much luck. Seem to be hitting brick wall after brick wall on this project :frowning: Anyone have any ideas?

Here is the players Move Right script:

	public float speed = 5.0f; //adjust in inspector
	
	void FixedUpdate () 
	{
		transform.position += Vector3.right*speed*Time.deltaTime;
	}
}

It’s hard to say without seeing how your scene and game object hierarchies are set up. Is the projectile moving at all? If so, is it moving in the right direction? Is the problem simply that it’s moving too slowly compared to the player? Try setting the player’s speed to 0 and see if you can isolate the problem.