Jump to content

Home

Arrow trajectory


XycaleTh

Recommended Posts

Posted

Hi, I've modded the game so I can fire an arrow from a long bow, but the problem I'm having is making the arrow point towards the direction its traveling in. If you fire the arrow as it is now at, say, a 45 degree angle, it will remain at 45 degrees until it hits an object and then sticks into it at the angle the arrow was traveling at as the arrow hit it.

 

So any ideas?

Posted

Maybe I didn't make myself very clear :s So here's a little diagram of what I'm trying to do ^_^

 

bow_shot.jpg

 

The first one is what's happening at the moment. The second one is what I want to happen :)

Posted

Found a possible solution, which I've based off the direction changing for the homing missile.

 

g_missile (G_RunMissile):

	if ( tr.startsolid || tr.allsolid ) {
	// make sure the tr.entityNum is set to the entity we're stuck in
	trap_Trace( &tr, ent->r.currentOrigin, ent->r.mins, ent->r.maxs, ent->r.currentOrigin, passent, ent->clipmask );
	tr.fraction = 0;
}
else {
	VectorCopy( tr.endpos, ent->r.currentOrigin );
}

Now looks like:

	if ( tr.startsolid || tr.allsolid ) {
	// make sure the tr.entityNum is set to the entity we're stuck in
	trap_Trace( &tr, ent->r.currentOrigin, ent->r.mins, ent->r.maxs, ent->r.currentOrigin, passent, ent->clipmask );
	tr.fraction = 0;
}
else {
	VectorCopy( tr.endpos, ent->r.currentOrigin );

	// [NDA] - Rotate arrow to simulate heavier arrow head
	if ( ent->s.weapon == WP_BOW && ent->s.pos.trType == TR_GRAVITY && !(ent->flags & FL_BOUNCE_SHRAPNEL) )
	{
		// We're still in the air
		VectorCopy (ent->r.currentOrigin, ent->s.pos.trBase);
		BG_EvaluateTrajectoryDelta (&ent->s.pos, level.time, ent->s.pos.trDelta);
		ent->s.pos.trTime = level.time;

		SnapVector (ent->s.pos.trDelta);
	}
	// [/NDA]
}

The arrow has FL_BOUNCE_SHRAPNEL added to its flags if it hit something at a very shallow angle so it doesn't stick.

 

I was hoping that it could be client-side predicted as well seeing as the arrow has a predetermined path. I'm happy with this solution but I'm sure there's a better one somewhere :p

Posted

So it works ok? You might want to look at the client side too to have it look smoother, the effect code as the projectile traveling is usually done in the client codes that start with fx_.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...