Hello,
I have looked up tutorials and topics and I tried it all. For some odd reason, I can’t make an instantiated object move.
I even made a new project to keep everything simple and test it out there.
I put in the First Person Controller, a bullet(sphere) and a gun( capsule).
Here is code I found on a tutorial using C#:
using UnityEngine;
using System.Collections;
public class Gun : MonoBehaviour {
public GameObject Sphere = null;
public GameObject Capsule;
public float fireSpeed = 500f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButton ("Fire1")){
Fire();
}
}
void Fire(){
GameObject Bullet1 = Instantiate(Sphere, Capsule.transform.position, Capsule.transform.rotation) as GameObject;
Bullet1.rigidbody.AddRelativeForce(transform.forward * fireSpeed, ForceMode.Impulse);
}
}
I understand what it all means. However, I don’t know if it’s Unity itself or maybe I’m still missing something, but I can’t get the object to move.
All it does is stay in the air. I’ve managed to make it fall before but now with this new setup, it doesn’t even do that which I assume has something to do with the rigidbody on it.
The transform.forward * fireSpeed should move it forward.
From what I know, you have a prefab. You make a copy of the prefab and set the position and rotation to whatever it is you’d like, so in this case, the gun. Afterwards, once it’s instantiated you add force to the object which then makes it go forward.
So from that, where am I going wrong? I greatly appreciate any help. I’ll even redo the entire code or set it up how exactly you want me to. I just need to understand where it’s going wrong.