Jump to content
  • 0

Can a projectile have its own speed combined with the player's velocity?


Mengo

Question

I want to make a flamethrower, and I want the projectiles to move at their speed as well as take in the player's velocity into account. So if you're moving at 50 forward, and you're firing the weapon, projectiles should go at 75, due to its own 25 speed, is this possible?

Share this post


Link to post

2 answers to this question

Recommended Posts

  • 2

Rummaging through the ZDoom Wiki a bit turns up A_ChangeVelocity, which might be what you're after. Logically, what you want to do is add the firing player's velocity to the projectile after it's fired. If I'm reading it correctly, leaving off CVF flags should add the provided values to the current velocity directly. But, I'm not sure how to actually obtain the values to add. The Actor Pointers page says "The following selectors expose fields for manipulation: AAPTR_MASTER, AAPTR_TARGET and AAPTR_TRACER." Which suggests you can do stuff like refer to AAPTR_TARGET.velx or something? (The one who fires a projectile is the projectile's "target" for some reason.) If so, then I'm guessing it would look something like this:

actor FlameProjectile
{
	States {
		Spawn:
			TNT1 A 0 A_ChangeVelocity(AAPTR_TARGET.velx, AAPTR_TARGET.vely, AAPTR_TARGET.velz)
			// then your own stuff
	}
}

Seems like there ought to be a better way to do it than that, but 🤷🏻‍♀️.

Also don't loop the Spawn state or it'll keep adding the player's velocity, rather than just once. Which... might make for an interesting way to control a projectile-in-flight with player movement, but that's not the intended behavior here. If it's just one frame, use a duration of -1; otherwise define a SpawnLoop state or something for it to loop back to.

Share this post


Link to post
  • 0
1 hour ago, Rainne said:

Rummaging through the ZDoom Wiki a bit turns up A_ChangeVelocity, which might be what you're after. Logically, what you want to do is add the firing player's velocity to the projectile after it's fired. If I'm reading it correctly, leaving off CVF flags should add the provided values to the current velocity directly. But, I'm not sure how to actually obtain the values to add. The Actor Pointers page says "The following selectors expose fields for manipulation: AAPTR_MASTER, AAPTR_TARGET and AAPTR_TRACER." Which suggests you can do stuff like refer to AAPTR_TARGET.velx or something? (The one who fires a projectile is the projectile's "target" for some reason.) If so, then I'm guessing it would look something like this:


actor FlameProjectile
{
	States {
		Spawn:
			TNT1 A 0 A_ChangeVelocity(AAPTR_TARGET.velx, AAPTR_TARGET.vely, AAPTR_TARGET.velz)
			// then your own stuff
	}
}

Seems like there ought to be a better way to do it than that, but 🤷🏻‍♀️.

Also don't loop the Spawn state or it'll keep adding the player's velocity, rather than just once. Which... might make for an interesting way to control a projectile-in-flight with player movement, but that's not the intended behavior here. If it's just one frame, use a duration of -1; otherwise define a SpawnLoop state or something for it to loop back to.

Thanks dude!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...