- Home /
Simulating Bullet Gravity using Raycasting
Hello, I am trying to find a way to simulate bullet gravity without rigidbodies. My initial thought was to raycast in the direction the Player is facing. Then I'd somehow check if the Ray would hit only on the x and z axis of another player. I would then send another raycast from the hit-point, direction Vector3.down, with the length of 0.5*a*t^2. Then I would check if the second ray hits another player. However, I have no idea how to check if the ray hit the player on only 2 axes, ignoring the height. Any help would be greatly appreciated. :)
Answer by Major · Mar 15, 2019 at 01:17 AM
You can achieve this by performing many raycasts over time to approximate the trajectory of the projectile. The length of a single ray or linecast is just how far the projectile can travel in 1 frame, or physics time step. The velocity vector of the projectile can be determined using v = v0 + at
, and the change in position s = 1/2at^2
.
This question has been answered on this thread as well.