Space Shooter Bolt Speed Forward Issue
Hello, I've been digging around in the site's past posts for an issue I have with what I believe the version changes with C# in the following step of the Space Shooter Tutorial:
Creating Shots : https://unity3d.com/learn/tutorials/projects/space-shooter-tutorial/creating-shots?playlist=17147
I'd made it to the last step of the tutorial where you test the bolts firing by entering the Game view
and then dragging the PreFab
item bolt into the Hierarchy
. The expectation was that the bolt should fire forward at a speed of 20. Unfortunately that is not the case. When I drag it into the hierarchy it just sits in place taking no action what so ever.
Here is the code that I'm using in my Mover.cs
file from the tutorial:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour
{
public Rigidbody rb;
public float speed;
void start ()
{
rb = GetComponent<Rigidbody> ();
rb.velocity = transform.forward * speed;
}
}
Any suggestions? I know the tutorials have depreciated to new code at this point, but I believe I'm doing this correctly yet no luck.
Thanks in advance.
Answer by MatchesMalone · Jul 28, 2017 at 02:24 PM
Okay, so I found my answer.
As it would turn out, the only thing that was wrong in my code was that "start" should have been capitalized to "Start". The following code works just fine when I have it corrected.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour
{
public Rigidbody rb;
public float speed;
void Start ()
{
rb = GetComponent<Rigidbody> ();
rb.velocity = transform.forward * speed;
}
}
Answer by LSPressWorks · Jul 27, 2017 at 10:14 PM
What is actually happening?
"This is not the case." Doesn't describe the problem enough to help. I am assuming, since only a handful of things can happen that the shot isn't moving. Given the simple nature of the code, there are limited options to troubleshoot.
1: Are you pressing "Play"? Being in Game view doesn't make it go if that isn't pressed. Plop it in the design view, and when you press "play" it will switch to Game View. 2: Is the bolt constrained in any way? 3: What are the properties of the bolt's Rigidbody? Drag, mass etc. 4: Is it in view of a camera? Putting it into the hierarchy instead of dropping on the design side in view of a camera can lead to things having off screen coordinates.
Ah, sorry. You are correct. I updated the original post, but here is an update directly to your follow up questions too:
When I drop the bolt into the hierarchy it takes no action. It simply sits there without motion forward.
Play is pressed before moving the bolt into the hierarchy. I also tried before thinking maybe I missed that order of operation, but no change.
I do not believe the bolt is constrained in any way. There seem to be no other elements residing in the same space as the bolt.
The properties of the rigid body are as follows: – $$anonymous$$ass: 1 – Drag: 0 – Angular Drag: 0.05 – Use Gravity: Unchecked – Is $$anonymous$$inetic: Unchecked – Interpolate: None – Collision Detection: Discrete – Constraints – Freeze Position & Freeze Rotation: All unchecked for x, y, z
It is in view of the camera. When I drop the bolt into the hierarchy it does appear in my game view which is currently set to the only camera I have in my main scene.
I hope this helped to illustrate what I'm seeing better. Thanks for the assistance.
Your answer
Follow this Question
Related Questions
Getting two Objects to the same direction with different speed 0 Answers
Tanks Tutorial Image separating 0 Answers
Roll-a-ball Tutorial - Player Moving without input 0 Answers
"Moving the player" tutorial contains errors- please assist. 0 Answers
Sphere with rigidbody and playercontroller script stuck in plane and wont move 0 Answers