Changing Velocity of player when hit by Monster

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Aerosplinter
Posts: 98
Joined: Wed Feb 01, 2017 2:14 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Changing Velocity of player when hit by Monster

Post by Aerosplinter »

Is it possible to change the velocity of the player so that he goes up whenever he is hit, for example, by an uppercut of the enemy?
User avatar
kodi
 
 
Posts: 1361
Joined: Mon May 06, 2013 8:02 am

Re: Changing Velocity of player when hit by Monster

Post by kodi »

Code: Select all

override void damagemobj(actor inflictor, actor source, int damage, name mod, int flags=0, double angle)
{
	if(mod == 'uppercut')
	{
		self.vel.z += 50;
	}
	return super.damagemobj(inflictor, source, damage, mod, flags,angle
}
If you put this on a custom playerpawn in zscript it should work I think. Just need to use damage type 'uppercut' for whatever calls the attack.
User avatar
Tartlman
Posts: 226
Joined: Thu Oct 11, 2018 5:24 am
Location: meme hell
Contact:

Re: Changing Velocity of player when hit by Monster

Post by Tartlman »

Wouldn't it be better if you coded the functionality in to the monster? Maybe something like:

Code: Select all

TROO A 5 A_DoThing();
TROO A 0 A_AttackThing();
TROO A 0 { target.vel.z += 50; }
It would make it so that it launches enemies in infights as well.
User avatar
Aerosplinter
Posts: 98
Joined: Wed Feb 01, 2017 2:14 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: Changing Velocity of player when hit by Monster

Post by Aerosplinter »

Tartlman wrote:Wouldn't it be better if you coded the functionality in to the monster? Maybe something like:

Code: Select all

TROO A 5 A_DoThing();
TROO A 0 A_AttackThing();
TROO A 0 { target.vel.z += 50; }
It would make it so that it launches enemies in infights as well.
Is this code Decorate or ZScript?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Changing Velocity of player when hit by Monster

Post by Matt »

If it has semicolons after the state function calls it's ZScript.
User avatar
Aerosplinter
Posts: 98
Joined: Wed Feb 01, 2017 2:14 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: Changing Velocity of player when hit by Monster

Post by Aerosplinter »

Tartlman wrote:Wouldn't it be better if you coded the functionality in to the monster? Maybe something like:

Code: Select all

TROO A 5 A_DoThing();
TROO A 0 A_AttackThing();
TROO A 0 { target.vel.z += 50; }
It would make it so that it launches enemies in infights as well.
Would something similar to this also work with DECORATE, but modified to fit DECORATE's language?
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Changing Velocity of player when hit by Monster

Post by Dan_The_Noob »

you could put a A_ChangeVelocity into the player pain state or something?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Changing Velocity of player when hit by Monster

Post by Matt »

[wiki]A_ChangeVelocity[/wiki] takes a pointer so the imp can do it to its target in that state.
Post Reply

Return to “Scripting”