Trouble using SetActorPosition and GetActorX/Y/Z

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
Ravick
Posts: 2049
Joined: Sun Aug 22, 2010 10:59 pm
Location: Tubarão, Brasil
Contact:

Trouble using SetActorPosition and GetActorX/Y/Z

Post by Ravick »

Hi there.

I was trying to mimic the 'walking' monster behavior with acs for any intended actor. I mean, it should 'pretend' the TAG actor was moving toward to the player who activated the script. I thought it'd be just check if actor's position coordinates were bigger or smaller the respective player's coordinates and just increase or decrease them according, repeatedly.

But it works... erradicly. Some actors does only move when player changes its Z coordinate, some actors moves outside the map, some does just move in one or two of the three coordinates, and some actors do not move at all. I have no clue of what I'm doing wrong. If someone could give some light here, it'd be appreciated. :)

The script follows:

Code: Select all

    
    int QualX;
    int QualY;
    int QUalZ;
    
 Script 6 (int Qual)
 {

// Defines X:
    If (GetActorX (Qual) < GetActorX (0))
        {
            QualX = (GetActorX (Qual) + 1.0);
        }
    Else If (GetActorX (Qual) < GetActorX (0))
        {
            QualX = (GetActorX (Qual) - 1.0);
        }
 
// Defines Y:
    If (GetActorY (Qual) < GetActorY (0))
        {
            QualY = (GetActorY (Qual) + 1.0);
        }
    Else If (GetActorY (Qual) > GetActorY (0))
        {
            QualY = (GetActorY (Qual) - 1.0);
        }

// Defines Z:
    If (GetActorZ (Qual) < GetActorZ (0))
        {
            QualZ = (GetActorZ (Qual) + 1.0);
        }
    Else If (GetActorZ (Qual) > GetActorZ (0))
        {
            QualZ = (GetActorZ (Qual) - 1.0);
        }
 
 //Sets new coords to QUAL actor:
    SetActorPosition (Qual, QualX, QualY, QualZ, 0);
    Delay (1);
    Restart;
 }
Thanks in advanced! :)
User avatar
TXTX
Posts: 195
Joined: Thu Sep 12, 2013 5:53 pm
Location: A Hidden Location

Re: Trouble using SetActorPosition and GetActorX/Y/Z

Post by TXTX »

Think there's a typo in the second part of defines x.
Both if and else lines have <. The second one should have >.
User avatar
Ravick
Posts: 2049
Joined: Sun Aug 22, 2010 10:59 pm
Location: Tubarão, Brasil
Contact:

Re: Trouble using SetActorPosition and GetActorX/Y/Z

Post by Ravick »

Humm... that explains some of the odd behavior. I guess the rest of it is because the script fails to put the actor in XYZ positions where it collides with level geometry. (It is a guess, however.)

Thanks :)
User avatar
TXTX
Posts: 195
Joined: Thu Sep 12, 2013 5:53 pm
Location: A Hidden Location

Re: Trouble using SetActorPosition and GetActorX/Y/Z

Post by TXTX »

You're right. Setactorposition doesn't force them to move to the position, only if it's open.

You might want to take a look at Warp. It is more flexible and you can force movement with one of it's flags as well.
https://zdoom.org/wiki/Warp

You can use it the same way by using the WARPF_ABSOLUTEPOSITION flag (to use coordinates).
User avatar
Ravick
Posts: 2049
Joined: Sun Aug 22, 2010 10:59 pm
Location: Tubarão, Brasil
Contact:

Re: Trouble using SetActorPosition and GetActorX/Y/Z

Post by Ravick »

It was way better indeed! Thanks! :D
Post Reply

Return to “Scripting”