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

Changed how entities collide with each other (fixes players pushing each other) #121

Merged
merged 3 commits into from
Oct 26, 2023

Conversation

NancokPS2
Copy link
Contributor

@NancokPS2 NancokPS2 commented Oct 25, 2023

Players are stopped by NPCs and enemies.
Enemies are stopped by NPCs and players.
NPCs are not stopped by anything.
They all still collide with the world.

Entities no longer exist on the J.PHYSICS_LAYER_WORLD and merely use their mask to collide with it.

It was necessary to add the ability for the ConditionLeaf "IsInCombat" to filter targets by type instead of choosing ANYTHING entering their area. (it caused enemies to attack each other lol)

Tests performed:

  • Try to aggro multiple enemies, they will not block each other and will just walk trough. They will still collide with the player.
  • Attempt to get in the path of a moving NPC, the NPC just pushes you aside

NPCs push aside any enemy and player they walk into;
Enemies only collide with players and NPCs
@NancokPS2
Copy link
Contributor Author

Closes #103

@jonathaneeckhout
Copy link
Owner

Will test it functionality wise.

The pipeline is failing due to not conform with code styling:

Some files in specified directories are not well-formatted. Please run 'gdformat' to fix them:
would reformat scripts/classes/JBody2D.gd
1 file would be reformatted, 0 files would be left unchanged.
Error: Process completed with exit code 1.

gdformat is a tool from gdtoolkit

@NancokPS2
Copy link
Contributor Author

How do fix this exactly? is there a git command or some more detailed message for the error?

@jonathaneeckhout
Copy link
Owner

How do fix this exactly? is there a git command or some more detailed message for the error?

So in this case gdformat tells you:

gdformat -d JBody2D.gd 
would reformat JBody2D.gd
--- JBody2D.gd
+++ JBody2D.gd
@@ -24,9 +24,10 @@
 	stats.name = "Stats"
 	stats.parent = self
 	add_child(stats)
-	
+
 	#Call this at the last moment, prevents possible errors from non-ready collisions and allows overriden _init methods to run first.
 	_init_collisions.call_deferred()
+
 
 func _init_collisions():
 	#Each creature only exists on their own layer, they collide with the world thanks to their collision_mask
@@ -37,28 +38,28 @@
 			collision_layer = J.PHYSICS_LAYER_ENEMIES
 		J.ENTITY_TYPE.NPC:
 			collision_layer = J.PHYSICS_LAYER_NPCS
-			
+
 	if J.is_server():
 		#By default, only collide with the world. No other entities.
 		collision_mask = J.PHYSICS_LAYER_WORLD
-		
+
 		#Set what it will collide with
 		match entity_type:
 			#The player cannot walk past NPCs and enemies. But other players cannot block their path.
 			J.ENTITY_TYPE.PLAYER:
 				collision_mask += J.PHYSICS_LAYER_ENEMIES + J.PHYSICS_LAYER_NPCS
-			
+
 			#Enemies can be blocked by NPCs and players.
 			J.ENTITY_TYPE.ENEMY:
 				collision_mask += J.PHYSICS_LAYER_PLAYERS + J.PHYSICS_LAYER_NPCS
-				
+
 			#NPCs cannot be stopped by any entity.
 			J.ENTITY_TYPE.NPC:
 				collision_mask = 0
 	else:
 		# Don't handle collision on client side
 		collision_mask = 0
-	
+
 
 func attack(target: CharacterBody2D):
 	var damage = randi_range(stats.attack_power_min, stats.attack_power_max)
1 file would be reformatted, 0 files would be left unchanged.

But practically the easiest thing to do is to install gdtoolkit:
https://pypi.org/project/gdtoolkit/

and run gdformat on your file/

There is also a vscode plugin which I use.

@NancokPS2
Copy link
Contributor Author

Found it and isntalled it (might want to add it to the contributions guideline)
It was just some redundant line breaks, should be fine now.

@jonathaneeckhout
Copy link
Owner

Found it and isntalled it (might want to add it to the contributions guideline) It was just some redundant line breaks, should be fine now.

It's already there:

[Use Code Style for Scripts](https://github.com/jonathaneeckhout/jdungeon/blob/main/CONTRIBUTING.md#use-code-style-for-scripts)
JDungeon uses the code style defined by [GDtoolkit](https://pypi.org/project/gdtoolkit/). Use this tool to format your code. It can also be added as a plugin to VSCode.

@NancokPS2
Copy link
Contributor Author

Oh, my bad.
I just checked the guidelines and missed it somehow.

@jonathaneeckhout jonathaneeckhout merged commit 7e30d69 into jonathaneeckhout:main Oct 26, 2023
3 checks passed
@NancokPS2 NancokPS2 deleted the fix-colls branch October 26, 2023 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants