Page 1 of 2

Quick ACS Question

Posted: Fri May 30, 2008 1:43 am
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.

Re: Quick ACS Question

Posted: Fri May 30, 2008 2:07 am
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;

}

Re: Quick ACS Question

Posted: Fri May 30, 2008 2:09 am
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);

Re: Quick ACS Question

Posted: Fri May 30, 2008 2:44 am
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?

Re: Quick ACS Question

Posted: Fri May 30, 2008 2:49 am
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...

Re: Quick ACS Question

Posted: Fri May 30, 2008 2:51 am
by Kinsie
bagheadspidey wrote:Maybe GetActorAngle (100) >> 8 - 90 or GetActorAngle (100) >> 8 + 90 + 180?
Tried both, no luck.

Re: Quick ACS Question

Posted: Fri May 30, 2008 2:54 am
by bagheadspidey
negative thrust doesn't work either?

Re: Quick ACS Question

Posted: Fri May 30, 2008 2:57 am
by Kinsie
bagheadspidey wrote:negative thrust doesn't work either?
No, in neither "- 90", "+ -90" or "-(GetActorAngle (100) >> 8 + 90)" flavors.

Re: Quick ACS Question

Posted: Fri May 30, 2008 3:01 am
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.

Re: Quick ACS Question

Posted: Fri May 30, 2008 3:06 am
by Kinsie
Aw man, now I'm confused :(

Re: Quick ACS Question

Posted: Fri May 30, 2008 3:11 am
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.

Re: Quick ACS Question

Posted: Fri May 30, 2008 3:20 am
by Kinsie
Got it! Thanks!

Re: Quick ACS Question

Posted: Fri May 30, 2008 3:24 am
by Apothem
NP, glad I could help! Sorry about the confusing explanation :(

Re: Quick ACS Question

Posted: Fri May 30, 2008 3:25 am
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);

Re: Quick ACS Question

Posted: Fri May 30, 2008 3:25 am
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);
}