Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X2Effect_Knockback tile trace intersects with ground #1431

Open
furudee opened this issue Dec 24, 2024 · 2 comments · May be fixed by #1437
Open

X2Effect_Knockback tile trace intersects with ground #1431

furudee opened this issue Dec 24, 2024 · 2 comments · May be fixed by #1437
Assignees
Milestone

Comments

@furudee
Copy link
Contributor

furudee commented Dec 24, 2024

In X2Effect_Knockback : GetTilesEnteredArray, an if-condition fails to take ground tiles in account and then later prematurely exits the loop and causes KnockbackToLocation to not be where intended

From my limited testing case, a trace info from WorldData.GetAllActorsTrace returns two actors with following object archetypes:

BLDGKit_Floor_03x06_A
ARC_TWN_GroundPlaneAx16

if( TraceHitInfo.HitActor == FloorTileActor )
doesnt take into account if the actor is a ground plane.
FloorTileActor = WorldData.GetFloorTileActor(TempTile) returns same XComLevelActor for both object archetypes,
but only the first one is actually exactly the floor tile actor.

So it continues to the if-condition where it was not supposed to go,
and will fail the XComFracLevelActor(TraceHitInfo.HitActor) == none condition
Thus prematurely ending the for loop and setting the KnockbackToLocation at the ground plane.

For a fix, I suggest adding another condition to check if the tile is a ground tile, as so:

	if( WorldData.GetAllActorsTrace(StartLocation, KnockbackToLocation, Hits, Extents) )
	{
		foreach Hits(TraceHitInfo)
		{
			TempTile = WorldData.GetTileCoordinatesFromPosition(TraceHitInfo.HitLocation);
			FloorTileActor = WorldData.GetFloorTileActor(TempTile);

			if( TraceHitInfo.HitActor == FloorTileActor -----NEW-----> || WorldData.IsGroundTile(TempTile) <-----NEW------ )
			{
				continue;
			}

			if ((!CanBeDestroyed(XComInteractiveLevelActor(TraceHitInfo.HitActor), DamageAmount) && XComFracLevelActor(TraceHitInfo.HitActor) == none) || !bKnockbackDestroysNonFragile)
			{
				//We hit an indestructible object
				KnockbackToLocation = TraceHitInfo.HitLocation + (-OutAttackDirection * 16.0f); //Scoot the hit back a bit and use that as the knockback location
				break;
			}
		}
	}

Following picture before and after adding the new condition
test

furudee added a commit to furudee/X2WOTCCommunityHighlander that referenced this issue Dec 24, 2024
@furudee
Copy link
Contributor Author

furudee commented Dec 25, 2024

Please ignore the suggested fix, I was too hasty about it.
Everything works fine until units start phasing through walls since all tiles are ground tiles, obviously

My hypothesis still is that occasionally the WorldData.GetAllActorsTrace intersects with the ground, and isn't considered the floor actor so it fails the if-check. Seems to be so with curbs and building tiles

test2

I didn't find a function or a variable, that confirms if an Actor is a floor/ground or not

I suppose another proposed fix could be either raising the extends, so they don't collide with the floor
Or entirely remove the extends from GetAllActorsTrace call and rely on a line trace

I did a quick test making it a line trace, and it seemed to work as you would expect, units that didn't get knocked back before did so fine

Also despite what I've heard, units that are knocked down get up exactly where you expect them to, thus I don't think it's based on physics

@furudee furudee changed the title X2Effect_Knockback missing a condition resulting in wrong knockback location X2Effect_Knockback tile trace intersects with ground Dec 25, 2024
@Iridar
Copy link
Contributor

Iridar commented Dec 25, 2024

Having reliable knockback was one of the first things I wanted to accomplish as a modmaker, and yet somehow never managed to it. It sure would be great if you can tackle it.

furudee added a commit to furudee/X2WOTCCommunityHighlander that referenced this issue Dec 28, 2024
furudee added a commit to furudee/X2WOTCCommunityHighlander that referenced this issue Dec 29, 2024
…ack units can take fall damage and may fly over units, merging logic with visualization trees
@furudee furudee linked a pull request Dec 29, 2024 that will close this issue
@BlackDog86 BlackDog86 added this to the 1.30.0 milestone Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants