Grab/Thrust target towards the caller?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
DnB-Freak
Posts: 304
Joined: Sun May 19, 2013 12:09 pm

Grab/Thrust target towards the caller?

Post by DnB-Freak »

Hi again, community.
I'm wondering if anyone knows if there's a way for a monster to grab/thrust its target towards it.
The effect consider to be similar to A_RadiusThrust with negative force, but only for one specific target not an environment of targets.
I've searched at the forums for it without any progress.
It can probably be done with ZScript, but I'm in need of an example.
Spoiler:
How does the correct way look like? :|
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: Grab/Thrust target towards the caller?

Post by krokots »

Did you put it in a function and called it at least for couple of frames? If you call it once, it may be not enough to move the target because of the friction. Try something like this:

put some int to store the time spent on thrusting inside actor class

Code: Select all

int ThrustState;
bool IsThrusting;
create some state in which the actor do the thrusting ( :wink: )

Code: Select all

States
{

	GetOverHere:
		TNT1 A 1 ThrustTarget(50, 10);
		Loop;
}
the function, I did not look at the wiki, but your calculations seem to be alright

Code: Select all

ThrustTarget(int force, int duration)
{
	if(!target)
		SetState(SeeState);

	if(!IsThrusting)
	{
		ThrustState = duration;
		IsThrusting = true;
	}

	if(ThrustState > 0)
	{
		Vector3 thrust = Vec3To(target);
		target.Vel -= thrust.Unit() * 255.0 * force / max(target.Mass, 1));
	}
	else if(ThrustState == 0)
	{
		IsThrusting = false
		SetState(SeeState);
	}
	ThrustState--;
}
DnB-Freak
Posts: 304
Joined: Sun May 19, 2013 12:09 pm

Re: Grab/Thrust target towards the caller?

Post by DnB-Freak »

I was trying out the anonymous functions in decorate, but GZD doesn't recognize the math functions as they're for ZScript only.

I had to convert the entire Decorate to ZScript to get this working.

Anyhow, you gave me a solution I find very useful, Thanks :)

Return to “Scripting”