2D Scene Collision

No, it’s following the gravity :slight_smile: I guess now it needs some collider to stand upon.

Yes, note that if you set Size.Z := Max(1000.1, Size.Z); for both, then you either always or never have the collision (depending on some unknown to me factors). I’ll try to study this issue later. We seem to do exactly the same as physics_2d_collisions example does, but are getting wrong result. Colliders seem to have correct sizes. Could those be some scene settings in Castle Editor?

I have not changed anything in the editor except the translation z.
See “westbeach-gamestateplay”.

The Size.Z was a tip of Michalis, because Z must not be 0. But I don’t understand it with the collision.
Yes, I studied the 'physics_2d_collisions` example over and over and don’t see what is wrong.

But the example uses manually constructed Scenes and it works. The game uses Scenes derived from Design, and it doesn’t work. Some default values might have gone unnoticed. Or some global setting not set or set in a wrong way.

So, conclusion is Michalis should take a look at the scene properties in the editor because designed scenes do not work with collision or there should be some properties set extra in the editor?

No, of course he might help here out (and I’ve already played with settings in Castle Editor for some time - nothing obvious is missing), but we have to figure out what the code game does differently than the example.

Maybe it is because I have placed the Scenes under a Transform.
The ‘PlayerScenePhysics’ procedure causes strange behaviour with the Translation coordinates.
When I change direction the ‘direction’ scene jumps to another position, so the different Scene translations don’t follow the parent Transform Translation. When I switch off the procedure all scene translations are the same as the Transform again.

image

I tried to reference those directly yesterday, and it didn’t work :slight_smile: And overall, physics should work on Transform without any issues. I’ll give it another round hopefully today evening :slight_smile:

Thanks for your help.
The “jumping” scenes are strange though. Maybe this is another problem with the physics as I don’t understand why these only occur with the physics procedure.
But one problem at a time. The collision mission first.
:wink:

@Carring Please put the complete code+data somewhere public, so that I may help best. Apologies if you already put it publicly (from what I see you only send it to @eugeneloza ), direct me to it.

Best to submit it here on the forum (everyone should have a link to attach files in the forum posts since some time). Or place it on GitHub. As a last resort, upload zip anywhere and post a link here.

I understand you ask for my help, but admittedly this thread got long, complicated and I just got lost :slight_smile: I have a feeling you may use physics for something that doesn’t even need physics (and may be solvable by simple TFloatRectangle.Collides call), but I may be wrong.

Please point me to the complete code+data I can try on my own, and say where’s the problem.

I know FloatRectangle.Collides works but remember my topic "starling vs. castle-sprites :slight_smile:
It is too rough as it takes the largest sprite-scene in the atlas (for instance character walking with wide legs) and does not shrink/bound with a smaller scene (standing character).

I will try to find out how to upload the complete code this evening; data is a bit too large to put in the forum. :slight_smile:

I just send it to you by mail as it is 70mb and I can only upload 4 mb zip in the forum.

Mail subject is: 2D scene collision problem

Thanks for your help!

And sorry, I still didn’t manage to get a deeper research of your issue… It’s lying right before my eyes in the center of Desktop - but this week is kinda busy disorganized for me…

No problem, I am already happy you spent your valuable time to help me! :slight_smile:
I am sure I will encounter more problems that I need help with trying to find my way around CGE.
:wink:

The upload size has been increased to 100 MB and I hope @Carring can upload it here. This way others can help – I do not want to be a bottleneck :slight_smile:

I know TFloatRectangle.Collides works but remember my topic "starling vs. castle-sprites :slight_smile: It is too rough as it takes the largest sprite-scene in the atlas (for instance character walking with wide legs) and does not shrink/bound with a smaller scene (standing character).

If this is the reason why you use physics, then it’s not a good reason.

If you use .castle-sprite-sheet and the default bounding box is too large for you, you can:

  • continue using .starling-xml with TexturePacker for now.

  • or decrease the rectantangle size manually, by whatever is needed. E.g. using BoundingBox.RectangleXY.Grow(-10, -20).Collides(OtherRectangle) instead of BoundingBox.RectangleXY.Collides(OtherRectangle) .

Trying to use physics will not change anything here. Physics engine doesn’t calculate bounding box by default, and if you try to pass there BoundingBox you will land in the same problem.

If you have too large bounding box/rect, then you have to make it smaller.

I thought when I watched the white bounding box expanding and shrinking around the walking character in the editor that it would make the collision “corners” directly around the image (scene).
With BoundingBox.Rectangle I noticed there is always collision around the size of the maximum sized image, so it does not “look” at smaller images / scenes (for instance when the character is less wide with his legs), even not with starling-xml. So there is no real “bounding” box it appears?

With the physics thing you were my last resort. :slight_smile:

Thanks for increasing the upload size but it appears not to be 100 mb?

Which is why I say to use Grow(-10, -20) in my examples above. You need to make collision bounds smaller manually, at least in .castle-sprite-sheet without trimming.

Using physics does not help you here, and likely complicate things.

Hm that is 100 MB (100 * 1024 KB). Can I just upload what you send me through email here?

You could also upload it yourself wherever you prefer (Google Drive, Dropbox), or put on GitHub. I want 1. others to have chance to answer 2. others to benefit from answers :slight_smile:

Yes, sure.

Text is:
Character moves or holds by pressing arrow keys once.

With line 230 in the code switched off (MakePlayerPhysics) the character moves okay with all scenes following the parent Playerscene translation.

Problems:

With line 230 “on” and thus calling procedure MakePlayerPhysics the character slowly moves down (unwanted).

and now switching direction the scenes do not follow the parent PlayerScene translation anymore which results in’scene jumping’.

There should be collision between mouse scene (eye icon) and playerscene but there is not. What is wrong?

I am reposting here @Carring sample code (relevant to above question) with permission. It turns out I did not increase attachment size successfully on Discourse last time – now it is 100 MB, so your next attachments should work, if need arises.

Rescue_Island.zip (68.8 MB)

I’ll try to analyze the problem and answer this weekend (although if anyone can help, you’re more than welcome :slight_smile: ). Have a good weekend everyone :slight_smile:

1 Like

On compiling I noticed a message in the editor about max physics ticks, this maybe a clue?