- Home /
Bullet Not Working
When I press the space bar, a bullet is supposed to spawn and start flying off. But instead, a bullet spawns and then stays put. This problem is only true for the player though, and not other objects I have spawning bullets. Their bullets spawn and fly off like they're supposed to. The bullets have a constant relative force of 100 z, a drag of 10, and an angular drag of 0.05. Here is my script that spawns the bullets:
using UnityEngine;
using System.Collections;
public class BulletController : MonoBehaviour {
public GameObject BulletSpawn;
public GameObject Bullet;
void Update()
{
if (Input.GetKeyDown("space") == true)
{
Instantiate(Bullet, BulletSpawn.transform.position, BulletSpawn.transform.rotation);
}
}
}
Here is a picture of my original bullet's components:
https://drive.google.com/open?id=0B_HzgsC9lP3nNlAyS0tweGRtckE
And here is a picture of the clone's components:
https://drive.google.com/open?id=0B_HzgsC9lP3ncnBTT2NRTk1mR2s
(I don't know how to insert images)
What is wrong with my bullets?
If the bullets collide with the player, they are destroyed.
Answer by alexander11 · Jul 19, 2016 at 01:25 AM
Use Rigidbody.Addforce or Rigidbody.velocity that usually works.
Answer by MrRightclick · Jul 18, 2016 at 01:15 PM
Do you have a script on the bullets that gives them the force? It's kind of hard to say without seeing other than your spawning script, which looks fine. If you do have a script giving the bullets force, check the inspector that any public values are correct.
Also just a guess, but your bullets might collide with the player hitbox and stopping instantly because of that. Try disabling the hitboxes on bullets and test it out. If this is the case, you can then disable collision detection between two objects using https://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html or just simply by moving the bullet spawning point outside the player collider.
Sadly, :( this won't solve my problem. $$anonymous$$y spawn point for the bullets is not touching the player, and the only force given to the bullets is because of their constant force component. Thanks for responding!
If you pause the game in the editor, does that bullet have the correct constant force instance assigned and does not have is$$anonymous$$inematic set?
Does the rigidbody on the bullet have is$$anonymous$$inematic set to true?
Answer by KnightNobody · Jul 20, 2016 at 02:09 PM
@matthrewp Just a side note what might cause the problem is that you have gravity on but constraint movement on the y-axis. So this might conflict with the movement. As for the bullet's movement maybe try adding a script to the bullet using something like. rigidbody.addForce(vector.forward * projectilespeed, Forcemode.Force);
Something like this let me know I'd like to help :D
Follow this Question
Related Questions
bullets acting weird when spawn 2 Answers
Add velocity relative to ground? 1 Answer
trouble making a fast projectile 2 Answers
Why are these object passing through each other? 1 Answer
how to make a bullet reflect off a wall? 4 Answers