FPS Projectile

I’ve been using ProjectileInterval as a way to project a model from a startPos to an endPos. My true goal is to being able to project bullets straight to my target from my startPos. The problem I’m having with the ProjectileInterval is that it goes “up” into the air and back down, like an object being thrown. I’m wanting a direct straight line for the projectile to follow from the startPos to the endPos, no matter what duration I specify. If I give it a slow duration, it should still follow that straight line all the way to the endPos. I’m only wanting to use this for “instant” projectiles such as bullets, etc.

Am I using the right projectile for what I want to do? Either way, how do I do this? Also, if this has been answered somewhere else, please refer me to that post, I tried searching for a while and couldn’t find anything. Maybe my searching skills suck. @_@;

You just want a LerpPosInterval. That moves in a straight line.

David

I don’t see an endPos though? How do you set what direction you want to travel in? I see a “pos” and a “startPos”. It says “undocumented function”, so yeah. >_>

Edit

I figured it out. The “pos” is the endPos kind of. Thanks for the help. :slight_smile:

panda3d.org/manual/index.php/Lerp_Intervals

Thats where it is, not sure on how you go about a endPos other then have it deletes it self onces it “hits” a wall or if the duration runs out.

If I may ask, how are you deciding on your end-points? Are you ray-projecting them, and then only using the interval to create an expressive animation, with the results already computed?

No where close to that point yet, I’ve just started working on the projectiles so I’m simply manually setting the end points.

I’m getting a small amount of each “piece” accomplished piece by piece. Then creating simple classes around these items for the way I intend to use them. Like the Networking example I just recently posted in the Code Snipplets.

Eventually I’ll get onto the end positions that you’re talking about, as well as collisions with the items I’m attempting to hit.

Aah, fair enough.

When you get there, I suggest that you calculate the end-points for “instant” projectiles as “hitscan” weapons - just project a ray from the start-point in the appropriate direction, test for collisions, sort the collisions (if relevant; I think that it’s only irrelevant if you want to act on all collisions) and act on the results as desired (such as subtracting health from the first-collided object, if it’s an object with health).

I get what you mean in a way(since I’m not there yet :wink: ), but if I do that, then do I even need a projectile for that? I’m guessing not since those items are pretty much instant? I’d probably just need the projectile if I wanted to do something more visible like lasers, etc?

More or less, although you could also use an interval to represent tracers, or some other form of visible bullet (such as a stylised visualisation).

If you want “non-instant” projectiles, i.e. non-hitscan projectiles, then I’m not sure that intervals are the way to go - again, how do you decide on the end-point, especially when it becomes possible for an object to move into or out of the way of a projectile?

In those cases, I would suggest considering giving your projectiles a velocity attribute, and on each update changing their position based on their velocity, current position and the elapsed time since the last update. Collisions would then be a matter of providing a CollisionSphere (or other appropriate collision solid) for each projectile and having it respond to various types of collision, probably using a CollisionEventHandler and patterns such as “projectile-into-enemy” and “projectile-into-wall”. For greater stability you might, I think, have Panda respect previous transformations and use setFluidPos, although I don’t think that that should be called for unless you have rather low frame rates (in which case you may well have bigger problems) or projectiles that are very fast, but not fast enough for you to be happy with hitscan.

(If you do have such rapidly-moving objects, perhaps take a look at this manual page.)