Quick ACS Question

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
Kinsie
Posts: 7402
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Quick ACS Question

Post by Kinsie »

I want to make a script that thrusts the player to it's left. How would I acquire the current direction of the player, then tell ThrustThing or whatever how to do what I want? Thanks.
User avatar
bagheadspidey
Posts: 1490
Joined: Sat Oct 20, 2007 10:31 pm
Contact:

Re: Quick ACS Question

Post by bagheadspidey »

This isn't exactly what you are looking for, but It's close. It sends a thing (dummy player actually) in a fixed direction and sets it's angle to that direction. This should get you started though. The stuff near the bottom isn't important, it just takes care of states to make sure the thing does its running animation while you move it. This should give you an idea of how to calculate the angles, though. Also look up GetActorAngle.

Code: Select all

int move_n = 0;
int move_e = 0;
int move_s = 0;
int move_w = 0;

// catch movement keypresses
script 401 (void) { move_n = 1; }
script 402 (void) { move_n = 0; }
script 403 (void) { move_e = 1; }
script 404 (void) { move_e = 0; }
script 405 (void) { move_s = 1; }
script 406 (void) { move_s = 0; }
script 407 (void) { move_w = 1; }
script 408 (void) { move_w = 0; }

int move_counter = 0;

function void movePlayer(void)	// called by player loop script
{
	int moving = 1;
	int direction = 0.0;

	if (move_n && move_e)
		direction = 0.125;
	else if (move_n && move_w)
		direction = 0.375;
	else if (move_n)
		direction = 0.25;
	else if (move_s && move_e)
		direction = 0.875;
	else if (move_s && move_w)
		direction = 0.625;
	else if (move_s)
		direction = 0.75;
	else if (move_e)
		direction = 0.0;
	else if (move_w)
		direction = 0.5;
	else
		moving = 0;

	if (moving && isPlayerAlive())
	{
		if (move_counter % 16 == 0)
			SetActorState (999, "Run", true);
		SetActorAngle(999, direction);
		ThrustThing(direction>>8, 1, 0, 999);
	}
	else		
		move_counter = -1;

	if (++move_counter >= 256)
		move_counter = 0;

}
User avatar
Apothem
Posts: 2070
Joined: Sat Nov 29, 2003 7:13 pm
Location: Performing open heart surgery on an ACS compiler.

Re: Quick ACS Question

Post by Apothem »

use http://zdoom.org/wiki/GetActorAngle

And make sure to use >> 8 in parenthesis on it so you can just use it inside of thrustthing.

as such described in the wiki:

ThrustThing (GetActorAngle (100) >> 8, 50, 1, 0);
User avatar
Kinsie
Posts: 7402
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Re: Quick ACS Question

Post by Kinsie »

OK, I can get it to thrust to the right...

Code: Select all

script 802 (void)
{
   Log(s:"DIVING TO THE RIGHT");
   ThrustThing (GetActorAngle (100) >> 8 + 90, 20, 1, 0);
   ThrustThingZ (0, 32, 0, 0);
}
But since I'm stupid I can't figure out how to thrust to the left. Ideas?
User avatar
bagheadspidey
Posts: 1490
Joined: Sat Oct 20, 2007 10:31 pm
Contact:

Re: Quick ACS Question

Post by bagheadspidey »

What else did you try?

Maybe GetActorAngle (100) >> 8 - 90 or GetActorAngle (100) >> 8 + 90 + 180?

edit - or just make the thrust amount a negative value...
User avatar
Kinsie
Posts: 7402
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Re: Quick ACS Question

Post by Kinsie »

bagheadspidey wrote:Maybe GetActorAngle (100) >> 8 - 90 or GetActorAngle (100) >> 8 + 90 + 180?
Tried both, no luck.
User avatar
bagheadspidey
Posts: 1490
Joined: Sat Oct 20, 2007 10:31 pm
Contact:

Re: Quick ACS Question

Post by bagheadspidey »

negative thrust doesn't work either?
User avatar
Kinsie
Posts: 7402
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Re: Quick ACS Question

Post by Kinsie »

bagheadspidey wrote:negative thrust doesn't work either?
No, in neither "- 90", "+ -90" or "-(GetActorAngle (100) >> 8 + 90)" flavors.
User avatar
Apothem
Posts: 2070
Joined: Sat Nov 29, 2003 7:13 pm
Location: Performing open heart surgery on an ACS compiler.

Re: Quick ACS Question

Post by Apothem »

oy I know what the problem is. You have to write a function that will prevent the number from going negative. So instead of the number going below 0, it goes to the top of the byte angle value and subtracts, because that is what normally happens with it anyway. You can use the following function to do this:

Code: Select all

function int fixangle(int amount, int pnum) //amount is how much you're subtracting. Pnum is the playernumber
{                                                        //amount can be positive or negative, and you'll still get the proper results.
     int check = getactorangle(100 + pnum) >> 8;
      if ((check - amount) < 0)
     {
           return 255 + (check - amount); // add's the negative value (or leftover rotation) to the top of the byte angle
     }
     if ((check - amount) > 255)
     {
           return (check - amount) - 255; // resets to 0 and then adds the spill over if it's above 255
     }
     else
     {
           return check - amount;
     }
     return getactorangle(100+ pnum) >> 8; //if all else fails, it returns the actors current angle
}
and then with that you do

Code: Select all

thrustthing(fixangle( 64, playernumber()), 20, 1, 0);
and you're good.



EDIT: whoops, forgot about the inverse on the amount check. Fixed.
Last edited by Apothem on Fri May 30, 2008 3:07 am, edited 1 time in total.
User avatar
Kinsie
Posts: 7402
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Re: Quick ACS Question

Post by Kinsie »

Aw man, now I'm confused :(
User avatar
Apothem
Posts: 2070
Joined: Sat Nov 29, 2003 7:13 pm
Location: Performing open heart surgery on an ACS compiler.

Re: Quick ACS Question

Post by Apothem »

Okay, basically, the huge chunk of code that is in the beginning of my post fixes your angles if they go over the max byte angle or below 0. So to calculate your angle that you want to thrust all you have to do is

fixangle(whichdirectionfromtheplayer'sfacingangle, playernumber());

That's it. And you just put it into thrustthing like you were putting the angle there normally.

So instead of:

thrustthing(64, 20, 1, 0);

it's:

thrustthing(fixangle( 64, playernumber()), 20, 1, 0);

without it, it won't play nice with the player's angle very much.
User avatar
Kinsie
Posts: 7402
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Re: Quick ACS Question

Post by Kinsie »

Got it! Thanks!
User avatar
Apothem
Posts: 2070
Joined: Sat Nov 29, 2003 7:13 pm
Location: Performing open heart surgery on an ACS compiler.

Re: Quick ACS Question

Post by Apothem »

NP, glad I could help! Sorry about the confusing explanation :(
User avatar
bagheadspidey
Posts: 1490
Joined: Sat Oct 20, 2007 10:31 pm
Contact:

Re: Quick ACS Question

Post by bagheadspidey »

Kinsie wrote:
bagheadspidey wrote:negative thrust doesn't work either?
No, in neither "- 90", "+ -90" or "-(GetActorAngle (100) >> 8 + 90)" flavors.
by negative thrust i mean setting the "force" param to a negative value. I know it works for ThrustThingZ...
//ThrustThing (angle, force, nolimit, tid)
thrustthing(GetActorAngle (100) >> 8 + 90, -20, 1, 0);
Last edited by bagheadspidey on Fri May 30, 2008 3:26 am, edited 1 time in total.
User avatar
Kinsie
Posts: 7402
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Re: Quick ACS Question

Post by Kinsie »

Wait, no I haven't.

How have I boned this up? (with Apothem's chunk pasted in...)

Code: Select all

script 801 (void)
{
   Log(s:"DIVING TO THE LEFT");
   thrustthing(fixangle(128, 100), 20, 1, 0);
   ThrustThingZ (0, 32, 0, 0);
}

script 802 (void)
{
   Log(s:"DIVING TO THE RIGHT");
   thrustthing(fixangle(0, 100), 20, 1, 0);
   ThrustThingZ (0, 32, 0, 0);
}
Locked

Return to “Editing (Archive)”