- Home /
Bullet not moveing forward,Bullet not moveing
bullet script:
using UnityEngine;
public class Bullet : MonoBehaviour { private Rigidbody bulletRigidbody;
private void Start()
{
bulletRigidbody = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
bulletRigidbody.velocity = transform.forward * 12;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.CompareTag("Enviroment"))
{
Destroy(gameObject);
}
if (collision.collider.CompareTag("Enemy"))
{
//collision.collider.GetComponent<Enemy>().Damage();
}
}
}
Unity 2019.3.14
No constarains on Rigidbody
Velocity = 0, 0, 0
no errors in console
bullet in its place
Your code works fine, I just added it to a gameobject with a rigidbody and it works as is... I recommend doing a screen recording of what you are doing or at least uploading screen captures to show us your scene setup.
Answer by SteenPetersen · May 29, 2020 at 11:33 AM
This works fine for me, you sure you're attaching the script?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class TestScript : MonoBehaviour
{
[SerializeField] Rigidbody _rb;
private void Start()
{
_rb = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
_rb.velocity = transform.forward * 12;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.CompareTag("Enviroment"))
{
Destroy(gameObject);
}
if (collision.collider.CompareTag("Enemy"))
{
//collision.collider.GetComponent<Enemy>().Damage();
}
}
}
this script and $$anonymous$$e both dont work i tried printing a debug message to the consule in the fixedupdate after the veloctiy and it did work so the proplem isnt that that the script isnt attached to the bullet and i made sure that i have a rigidbody in my bullet
Things that could cause this:
TimeStep
Rigidbody $$anonymous$$ass is super high
Rigidbody is set to isKinematic
Your camera is attached to the gameobject and it looks like its not moving but actually is.
thanks very much the rigidbody was kinematic
Your answer
Follow this Question
Related Questions
C# Bullets do not fly, just fall... 3 Answers
What is wrong with this rigidbody? 2 Answers
Particle system rate by speed of vehicle 1 Answer
Unity relative velocity limiting 0 Answers
How would you check the local velocity of a rigidbody on a single axis 2 Answers