In the space shooter tutorial on the "creating shots" the bolt won't move

Hi im new to Unity and C#, and while doing the tutorial for the space shooter i got stucked beacuse on the las par of the session “creatin shots” the shots wont move and i don’t know why, i have the same code on the script.

Here is the code:

using UnityEngine;
using System.Collections;

public class Mover : MonoBehaviour 
{
	public float speed;

	void start()
	{
		GetComponent<Rigidbody>().velocity = transform.forward * speed;
	}

}

Any help will be really apreciated.

I’m also very new to Unity. I’ve made my own solution, try this, it worked for me:

	public float speed;
	
	void Start ()
	{
		Rigidbody rb = (Rigidbody)GetComponent(typeof(Rigidbody));

		Vector3 movement = new Vector3 (0.0f, 0.0f, 1.0f);
		GetComponent<Rigidbody>().velocity = movement * speed;
		
	}
}

this worked for me:

	public float speed;
	
	void Start ()
	{
		Rigidbody rb = (Rigidbody)GetComponent(typeof(Rigidbody));

		Vector3 movement = new Vector3 (0.0f, 0.0f, 1.0f);
		GetComponent<Rigidbody>().velocity = movement * speed;
		
	}
}

then you get the attribute “Speed” in the “Player” Object, in the “Script Inspector” Tab. I’ve set the value for speed to 10.

You can take the same code for the movement of the hazards, setting the speed on -4 or as you like.

Hope this helps!

void start()
{
GetComponent().velocity = transform.forward * speed;
}

Change to

 void Start()
 {
     GetComponent<Rigidbody>().velocity = transform.forward * speed;
 }

public float speed;

	void Start ()
	{
		Rigidbody rb = (Rigidbody)GetComponent(typeof(Rigidbody));
		rb.velocity =  transform.forward * speed;
		   
	}enter code here

Same i tried but not wroking…

Try this…`public float speed;

void Start ()
{
	Rigidbody rb = (Rigidbody)GetComponent(typeof(Rigidbody));
	rb.velocity =  transform.forward * speed;
	   
}`

My guess if the script isn’t working (what you posted should be fine) is a component was set to wrong object somewhere along the way. Make sure your Bolt prefab has both the Capsule Collider, Rigidbody, and Mover Script (and not the VFX child).

Your console should be spitting out errors like “Can’t find reference to Rigidbody” while playing and trying to load a Bolt if this is the case.

Hello! Try this Simple Code and After Saving your script, just make sure that the CheckBox of Is-Kinematic is DE-SELECTED on Rigidbody component in Inspecteor.

public class Mover : MonoBehaviour {
public float Speed;
private Rigidbody rb;

void Start () {

	rb=GetComponent<Rigidbody> ();
	rb.velocity = transform.forward * Speed;
}

}
Hope this will work, cuz me too was sufferring from this Error and now it is working.

I removed my typed script and replaced it with Done_mover in the Done folder, and the bolt moved as in the tutorial. I went back and compared the two files, and found out that I typed the following in my Mover script:

void start() {
GetComponent().velocity = transform.forward * 20;}

Turns out the start function is case sensitive and should have been Start. I guess there’s a overloaded start function somewhere. Check for that stuff if anyone else runs into these types of problems.

this help me on unity 5.5.2

public float speed;

void Start ()
{

	GetComponent<Rigidbody>().velocity = transform.forward * 20;

As nmathis noticed, the bolt object was rotated 90 degrees about the x-axis in the case of the never version of Unity (I’m using the 2017 version, and this remains the case). Rotating 90 degrees about x-axis makes it so that the object’s forward.transform, in terms of the global coordinates, is on the y-axis instead of the x-axis.

What worked for me was to rotate the VFX around the x-axis by 90 degrees to return the rotation of the Bolt to 0 degrees about the x-axis . This way the object is treated as un-rotated and the result of transform.forward is in the direction of the z-axis of the scene, as expected.

Sorry to revive this old thread, just thought the info might help as I was similarly confused!