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

Raycast Node stops detecting collisions #40952

Closed
xavierocampos opened this issue Aug 1, 2020 · 11 comments · Fixed by #41426
Closed

Raycast Node stops detecting collisions #40952

xavierocampos opened this issue Aug 1, 2020 · 11 comments · Fixed by #41426

Comments

@xavierocampos
Copy link

xavierocampos commented Aug 1, 2020

Problem found in version 3.2.2 in Windows 10.

I was developing a project and I was having a problem with the movement of enemies that I posed in various ways until one day I decided to activate the collision forms to see what was happening on screen and it turns out that the Raycasts at a certain point and for some strange reason start popping as if they stop detecting collisions, so that's where the problem really was, that the Raycasts stop working.

There's no need to share code because it's not the code, but at some point and for some strange reason, they just stop working.

Here I share some screenshots, first when you start the game, everything is fine, you can see how the Raycasts are in red and work properly.

image

But as soon as things start to happen on screen, it starts that popping and it doesn't detect collisions anymore.

image

The ones below are normally not detecting collisions, but notice that the enemies on the top row should detect them and no longer do.

I share with you an example project so you can review it, with the visible collision forms move with the direction keys of the keyboard and shoot the ball with the space key, you will see how the calculations of the Raycasts are broken at some point and they stop working.

Test Project

EDIT: I found the problem. It's not when anything happens, but one thing in particular: When the ball moves.

The ball is not a RigidBody (I don't like the behaviour of physics very much and it's difficult to adapt it to my tastes) but a KinematicBody that moves with move_and_collide, I've been looking for and correcting myself if I'm wrong but I've researched and read other people who indicate that when they have a Raycast touching the ground while moving the node with move_and_slide or move_and_collide the Raycasts start giving wrong behaviours, that's when I said "it's true! the ball moves with move_and_collide!"

I just tried a RigidBody and indeed, the fault does not occur. Anyway, it wasn't just about fixing the problem in my project, but about fixing the problem in Godot in general because after that I think I can say that we are actually facing a pretty important problem.

EDIT 2: New correction, it keeps happening even if you put the ball as RigidBody, it happens less, but it keeps happening because finally the player is a KinematicBody and it moves with move and slide... I definitely think this problem is a mess...

@girng
Copy link

girng commented Aug 1, 2020

Might help with a tiny example project so devs can trigger it and fix it

@xavierocampos
Copy link
Author

xavierocampos commented Aug 2, 2020

Might help with a tiny example project so devs can trigger it and fix it

I have the project somewhat advanced, I'm going to prepare a primitive version of the project where you can appreciate the error so you can have it as a reference. I'm talking about the lack of knowledge but I have the suspicion that the problem comes from the amount of Raycasts that are on the screen simultaneously and the problem is not solved by activating and deactivating the Raycasts at the right time, on the other hand if there are only 2 or 3 enemies as I say it works perfectly, that's for sure, as long as they are 2 or 3 from the beginning because if from the beginning there are many and they are reduced to 2 or 3, once the Raycasts start to fail they don't work correctly again in the course of the game.

Edit: I just uploaded it, edit the first comment and the link appears until the end, I hope it helps because if it's a problem with the Raycasts, I think the functioning of the Raycasts is of vital importance for almost any project.

@Calinou
Copy link
Member

Calinou commented Aug 2, 2020

Can you reproduce this in any earlier Godot versions such as 3.2.1, 3.2 and 3.1.2?

@xavierocampos
Copy link
Author

xavierocampos commented Aug 2, 2020

Can you reproduce this in any earlier Godot versions such as 3.2.1, 3.2 and 3.1.2?

Yeah, I actually forgot to mention that. I tried it in version 3.0.6 (to be tested) and obviously it didn't open the project in this version, but it did from version 3.1.2 and the problem persists although at least the inconvenience is already located: The Raycasts are not good friends of the KinematicBodies who make use of the move and collide / move and slide methods and it seems that this is happening since several versions back.

@xavierocampos
Copy link
Author

@Calinou It's not about reporting a problem with my project, it's about reporting a problem with Godot, if the Issue is closed it won't have visibility and they won't even try to review it. It must be open so that it can be seen and reviewed, that's why I uploaded the project.

@xavierocampos xavierocampos reopened this Aug 2, 2020
@Calinou Calinou removed the archived label Aug 2, 2020
@xavierocampos
Copy link
Author

xavierocampos commented Aug 6, 2020

@akien-mga An apology for being insistent but if I don't insist, you won't see the problem and I think it's an undetected problem but one that you can check when you download the project I uploaded. I have tried several solutions but the problem is always the same: The Raycasts don't work in certain cases, as they don't detect the collision because of that "popping" the collision returns false and I can keep going over it to change the condition and force it to require a true, but it's not about solving the problem in my project, but that the Raycast nodes work correctly so that I don't have to resort to tricks, because honestly and after so much time thinking about it until the failure is detected, I have even considered the idea of redoing the project with Unity because it is complicated to deal with failures that escape my hands (since I am not an expert and I cannot solve engine problems on my own).

Edit: I have to add that the problem persists even in the RC versions of 3.2.3, since as a desperate measure I tried to test the RC to see if by chance it didn't happen in these, but yes, it also happens.

@akien-mga
Copy link
Member

CC @madmiraal

@madmiraal
Copy link
Contributor

madmiraal commented Aug 21, 2020

@xavierocampos This is related to #41031. You have at least one CollisionObject which has either at least one dimension scaled to 0 or has a parent Object that has at least one dimension scaled to 0.

In the Test Project the Player's Ball's KinematicBody is scaled to <0, 0, 0>. But there are others, for example, the Player's Shield's StaticBody is also scaled to <0, 0, 0>. Make sure that all CollisionObjects, and their parents, do not have any dimensions scaled to 0. In fact, don't scale them at all, change the size of the Meshes and the CollisionShapes instead.

@xavierocampos
Copy link
Author

xavierocampos commented Aug 21, 2020

@xavierocampos This is related to #41031. You have at least one CollisionObject which has either at least one dimension scaled to 0 or has a parent Object that has at least one dimension scaled to 0.

In the Test Project the Player's Ball's KinematicBody is scaled to <0, 0, 0>. But there are others, for example, the Player's Shield's StaticBody is also scaled to <0, 0, 0>. Make sure that all CollisionObjects, and their parents, do not have any dimensions scaled to 0. In fact, don't scale them at all, change the size of the Meshes and the CollisionShapes instead.

@madmiraal I thank you very much for the answer, yes, the objects that have a scale of 0, 0, 0 is because they have an AnimationPlayer node to hide/show them, but as I understand from what you say even if during the execution of the game the scale changes from 0 to 1 that affects something and preferably we should avoid touching the scale, right?

I'm going to try it in the same Test Project to not alter the original project and see if it works well.

Update: I've just updated the test project correcting those details you mentioned and I think it's correct, I tried a couple of times and it seems to be solved so I thank you again although it's not weird? I mean it's good to know that detail to avoid problems, but if the scale affects so much to other components wouldn't it be better to eliminate the transform scale?

As I say I speak from ignorance, I'm learning and every new thing I learn is very grateful and is a step further, but I think that leaving an option that use it can give problems is only giving the option to the developer to cause these problems, of course if there is a powerful reason to leave the transform then I better shut up hehe

Update 2: There, I think I understood better after spending some time testing just to understand how it worked. Yes, it does make sense to scale, I can scale a mesh and nothing happens, I can scale a spatial, but not scale physical nodes. Definitely a lesson learned, thanks!

@Zireael07
Copy link
Contributor

No, you do can touch the scale but you should generally avoid scaling to 0,0,0 and you should definitely NOT scale physics bodies.

@xavierocampos
Copy link
Author

No, you do can touch the scale but you should generally avoid scaling to 0,0,0 and you should definitely NOT scale physics bodies.

Yes, thank you, I will certainly take that as a lesson learned without a doubt.

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.

6 participants