Hello, I am new to Godot and I am a bit confused by singals and collision. I hope I can get some help.
My Questions are:
How can i use Signals for Collision and make my Object “solid” so its not entering but colliding
Is this a good way and if not: why and what would you do better? (currently is not colliding but entering the area, but except that)
func spawn(enemyName: String) -> void:
var enemyScenePath = "res://models/" + enemyName + ".dae"
ResourceLoader.load_threaded_request(enemyScenePath)
loadEnemy(enemyScenePath)
func loadEnemy(enemyScenePath: String) -> void:
var newEnemy_scene = ResourceLoader.load_threaded_get(enemyScenePath)
var newEnemy = newEnemy_scene.instantiate()
var thisWorld = $"."#world
thisWorld.add_child(newEnemy)
#newEnemy.rotation_degrees = Vector3(0, 70, 0)
#newEnemy.scale = Vector3(3,3,3)
var enemyArea3D = Area3D.new()
var collisionShape = CollisionShape3D.new()
var shape = BoxShape3D.new()
shape.size = newEnemy.scale
collisionShape.shape = shape
enemyArea3D.add_child(collisionShape)
newEnemy.add_child(enemyArea3D)
enemyArea3D.body_entered.connect(enemyBodyEntered)
func enemyBodyEntered(_body: Node3D) -> void:
print("test")
I know that those questions must seem stupid, but i rly tried to get to a solution on my own with the help of the documentation and at least the code above is working.
Have a great Day.
Use RigidBody3D or CharacterBody3D instead of an Area. Area’s don’t “collide” but they can detect physics objects collisions with its collision shape. think of Areas as a proximity sensor.
Thanks, i did it with the Signals of the RigidBody3D but how would i do it with the CharacterBody3D, it does not have any singals in the doc. Do I rly have to use one of the gets for collision, doesnt seem efficent, or am i wrong?
Characterbody are a little more complicated but the do have a means for detecting collisions. I don’t know if I can help readily as I have never used one.
And yes you need collisions and collision signals are the best way to get the event. The physics engine is written in C++ so it is also probably as efficient as it could be. There is no other way to detect a collision without physics bodies or a physics engine.
I was thinking about this a little more and was wondering if there was some misconception oh how collisions work.
Basically I wanted to make clear is that you don’t need to worry about handling collisions they will always work.
If you want to know a collision happened, like a weapon hitting an enemy to then deal damage. Collision signals are the best way to get notified of a collision. Yes you may have to deal with other non damaging bodies coming through the signal, but there can be collision layers and masks to optimize this.
I did now implement a working “hitting the enemy”(with RigidBody3D), but the problem that stayed was why does the CharacterBody3D doesnt have Signals and only has those weird gets like
KinematicCollision3D from the get_slide_collision(int slide_idx)
even tho i could make this work with the Characterbody3D now.
The simpel fact that its does not have signals by default is confusing.
I dont understand why i mean it has to have a reason?
Like i can detect collision with those get methods but it feels wrong, but i did it now with the RigidBody3D because it felt more fitting for the purpose but i hope you get where the confusion comes/came from.
I haven’t used character bodies, but they let you do all kinds of movement that be really hard to do with force based rigidbody.
I bet there is some signal you could setup, I just haven’t looked at the docs in a while.
I wanted to share something about hitbox and hurtbox design. These are typically built with areas. And for an great example take a look at smash brothers videos that have hacked the game to expose the boxes. After a opponent is hit the force is given to the underlying character body (or rigidbody).
CharacterBody3D collisions are detected in the move_and_slide() and move_and_collide() methods, not via signals. They are not controlled by the physics system in the same way as RigidBody3D, but are controlled directly by your code.