TryMove not moving 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!)
KiddTheIdiot
Posts: 2
Joined: Tue Jun 02, 2026 2:01 pm
Operating System Version (Optional): Windows 11

TryMove not moving the caller

Post by KiddTheIdiot »

Hi there! I'm trying to make a monster move to their target's last recorded position via TryMove, although the monster doesn't seem to be moving at all. The rest of their states work, but they just don't want to move. Here's the code that involves TryMove for reference:

Code: Select all

	See:
		SPOS AABBCCDD 6
		{
			Vector2 targetPos = target.pos.xy;
			if(target != null)
			{

				self.TryMove(targetPos, 0, false, null);
				A_Print("I moved!");
			}
		}
		Goto Missile;
If there's anything wrong with the code, please help me out! It means a lot!
- KiddTheIdiot
Kan3x
Posts: 79
Joined: Tue Nov 08, 2022 4:19 pm

Re: TryMove not moving the caller

Post by Kan3x »

because you're not trying to move it to the last "recorded position", but to the target's current position, resulting in TryMove to fail because the position is occupied by the target (if both solid).

Also, TryMove is not a mare "telportation" kind of function, but it will actually try to check if the caller can "step" towards that position, which means if the difference between the heights of the sector the target is in and the sector the caller is in is bigger than the caller MaxStepHeight, it will fail, the same for the opposite scenario (and if the caller does not have NODROPOFF flag, FLOAT etc.) and several other checks.
You're also passing "0" as the second argument, meaning that if the target is even 1 map unit above/below the caller it will fail (unless it means something else, but the wiki does not say anything about it).

I don't know what your intent is here, but to teleport actors with impunity you should use SetOrigin instead, but again, I do not suggest you to teleport directly at the target location, of course, because they'll both get stuck in one another.

You should 1st: get a position close to the target but outside its hitbox, check if the position is valid and only then teleport the guy.

(you're also getting your targetPos vector2 by getting the target position without checking if the target != null, move the check above it)
KiddTheIdiot
Posts: 2
Joined: Tue Jun 02, 2026 2:01 pm
Operating System Version (Optional): Windows 11

Re: TryMove not moving the caller

Post by KiddTheIdiot »

I'm not trying to teleport the monster to the target. I just want him to walk there, which is why I used TryMove. Thanks for explaining the second argument though, I couldn't really understand it.
Kan3x
Posts: 79
Joined: Tue Nov 08, 2022 4:19 pm

Re: TryMove not moving the caller

Post by Kan3x »

Yeah, we don't have many info nor examples about TryMove unfortunately D:
KiddTheIdiot wrote: Wed Jun 10, 2026 3:17 pm I'm not trying to teleport the monster to the target. I just want him to walk there, which is why I used TryMove.
and that's why you cannot achieve this with just this function, for TryMove will directly teleport (if every check passes) the caller to the xy position you specify in its arguments.
If you want you actor to walk there, you first need to calculate the entire vector from the caller to the target, then you have to get just a segment of that vector = to the caller speed and move the caller by that segment on every call.

something like this:

Code: Select all

vector2 stepToTarget = level.Vec2Diff(pos.xy, target.pos.xy).Unit() * speed;
TryMove(stepToTarget, MaxStepHeight);
although, this will lead the caller to get stuck against every obstacle he finds on the way, because there's no "backup plan" in just TryMove
so you probably want something like

Code: Select all

[...]
if(!TryMove(stepToTarget, MaxStepHeight)) A_Chase();
if you want to keep things simple, otherwise you have to make all the obstacles etc. checks by yourself, basically make a new A_Chase function

Return to “Scripting”