- Home /
Other
How can a object be prevented from falling ?
I tried to make projectile for a Spaceship for 3D game. But whenever I instanitate an projectile and make it move, ıt falls . I assume because of rigidbody but couldn't find how to fix. I want projectile to move forward and not fall.
Those are components of projectile
Those are codes I used to keep projectile from falling.
public class Projectile : MonoBehaviour
{
void Update()
{
//transform.position += new Vector3(-1, 0, 0) * 0.1f;
//GetComponent<Rigidbody>().velocity = -transform.right * 100 * Time.deltaTime;
//GetComponent<Rigidbody>().AddForce(transform.up * 0.000001f);
}
}
Answer by Lifes_great · Mar 06, 2021 at 07:51 AM
just turn off use gravity :D
it's not what I want. If ı turn off gravisty, the projectile flies in scene
What do you want then ? From what I understand Lifes_great is right. If you want your projectile not to fall juste uncheck use gravity in the Inspector. Then just add a forward force in the same place where you instantiate the projectile. Something like this should work :
GameObject bullet = GameObject.Instantiate(projectile, transform.position, transform.rotation); bullet.GetComponent().AddForce(weaponCam.transform.forward * shootForce);
Follow this Question
Related Questions
Bullet won't fly forward 1 Answer
Move object along ray cast using object's AddForce or velocity but not transform 1 Answer
different beetween transform.translat and rigidbody.addforce? 1 Answer
How can I move an object a specific distance using AddForce? 2 Answers
2D character can't jump off of platform floating in water 0 Answers