- Home /
how to make a ray moving in a trajectory way.
Hi I'm a bit new to programming. I'm testing if i can build a simple aim and shoot fps kind of a game. which i fell into a ditch.
i want to make a ray,that moves like a trajectory in a 3d game.starting from the main camera,and stops when hitting on to the plane.
I've worked out how to shoot a ray and destroy an object. but i couldn't seem to find a solution to a parabolic kind of ray.
void Ray() {
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(mouseRay.origin,mouseRay.direction,Color.red);
RaycastHit hit;
if(Physics.Raycast(mouseRay, out hit, 10.0f, mask))
{ Destroy(hit.collider.gameObject); } }
it would be nice if i could get a help thx for your time. XD
Answer by FortisVenaliter · Jan 27, 2016 at 07:58 PM
Rays are, by definition, a straight line. If you want to do a parabola, you need to calculate the physics yourself. Usually this is done either by breaking the trajectory into line segments, or (if the projectile is moving slow enough) by running physics calculations on it each frame.
ah, so I need to ...?
1.shoot a short ray.
2.get a starting point and the Endpoint of that ray.
3.rotate the ray in a certain degree and shoot another ray from the Endpoint of the 2.ray.
4.repeat till it goes beyond a certain distance from the first ray stating point or it hits some thing.
5.return a raycasthit and get a game object.
That could work, but I would use ballistic equations to calculate the actual curve, then use some calculus to split that into accurate segments, and run them through the physics engine one by one.
Your answer
Follow this Question
Related Questions
Problem With Raycasthit Angle 0 Answers
Something fishy with RaycastHit 1 Answer
Rays do not detect terrain and prefabs do not spawn where wanted 1 Answer
How can I can I cast a ray from a gameobject? 1 Answer
Raycast Not Working 3 Answers