Using Raycasting to lob a projectile.

Hey there UnityAnswer Users.

I have a Question… (Ironic?) anyway to the point.

I’m currently making a first person catapult game.

EDIT: I wish to use raycasting to cast a circle on the ground so that when a projectile is fired it will go to where the circle has been cast. The cast circle needs to be controled by using w,a,s,d. I also need to have the projectile fire with a lobbing effect (Like a catapult) when “space” is pressed.

I need to be able to select 3 different projectiles using Keys “1,2 and 3”

Any help would be much appreciated. Even hints on what to do would be great.

Thanks in advanced, Castleforce. (Trent)

EDIT: If any feed back I’m coding in Java… (Only code I know, though I’m really bad)

I’m not sure I understand fully. If you are asking how to raycast you can use Physics.RayCast() and it’s pretty straightforward to get the position to launch at.

If you are asking how to correctly lob the projectile you can either do some physics math to figure out the correct velocity to get your projectile to the end point with your current angle (this might be kind of difficult depending on how sharp you are with this sort of thing) or you can just kind of hack it and make a Bezier Curve that simulates what the trajectory would be and just move it along that. Bezier curves are pretty easy to implement and it’s a useful thing to have access to.

The simplest way to hack a curve is to add a porabola to your Y axis. so it goes up and comes down the Y while travelling along the XZ in a straight line.

this will give you a predictable lob.

if you want a physics driven approach check projectile equations in wikipedia