[SOLVED] Adaptative object depending on collide

Hi, in my conquest of masterising Gdevelop.
I’m now face to a new mechanic.

I’m trying to use “Point is inside”

image
Let admit there is 4 cardinal point North (N) South (S) West (W) and East(E)
And i’m building a 4 way Rail

I want an Object to react like that .

In the exemple N and W are connected, so i want the Object to swap for “Turn Left” Tile.

The swap isn’t a problem, but the point inside seem to don’t work as i want.
My problem is probably coming from the fact that i’m trying to see if a point of 4 Way is inside 4 Way.

I don’t know if it’s clear enough.

In the end i want an adaptative way to build a train rail depending and what is near to create the correct tile.

I look at this post [WIP] FORESTFUL [Updated JULY 13] Finished ground merging algorithm (downloable example)
But it seem way too complicated for what i want, and i need it to run in game not in the builder.

edit:I forget to precise, i need to setup “the road” with a generic marker object and then convert every marker to match the requierd Tile depending on connection point

Pathing
something in this idea
Thanks

1 Like

Thanks for looking at that old project post of mine.

You’re right, that thing is somewhat overcomplicated and not polished. There even was a much more efficient unpublished version of it.

However, it’s not necessary to use my ground merging method for what you want, at all.

I recommend you to set all your game in a strict grid to keep track of what’s located in every cell.

In that way you can check what’s above, below, at the left and right sides, and even diagonals of a specific cell and adapt it to it.

Hi thanks for answering,
I think i can track information but i dont get how it will read that info and then use a rules de make thing work.

Is there a way to check if there is an object at x+1 ?

What you describe is more or less AutoTile system
Look what i did here

Order of events + which object is called where is crucial
FOR EXAMPLE

If i change for each event to check red it won’t work

And using that trick you would need to have 2 objects
ONE will be object that stay on floor let’s call it tracks
Where 2nd object is there just as some kind of indicator and let’s call it that
So imagine you put indicator object above track object
You check like i did if any tracks object is next to indicator object
Depending on how many objects are there you pass some variable for example scene variable to yourself
Like for each tracks next to indicator object you add 1 to scene var

NOW you create tracks object in place of indicator object and depending on scene var you change animation of tracks object to whatever
Where you need to prepare animations for all possible combo
Straight shape of tracks L shape T shape and cross shape where for line L and T shape you need to have it for every possible rotation
Last step is delete indicator object
And rest is setting up in events what should happen if something moves or collides with tracks depending on its animation

It will be a bit of work and maybe it is too much for what you want to achieve so maybe let’s wait for someone to come up with more simple solution

ok you give me an idea.
i could create all my track road
Then i pop indicator up, left, down, right, delete them and, if they collide with another track, stock i in variable, then set up the tile un want, corresping to each combo of var.
I will try that soon.

Thanks

You could that by creating each track type as separate object
Or as i suggested making one track object and changing animation
How you gonna do it is up to you
But both methods will end up in same result
Difference is how you gonna get there
You could prepare events to change animation of track to whatever value of track variable is
But then you still need to set up some way so if there is track above and below newly placed track it do not return same value as if there is track on left and right

One way to do it is

Basically you want to look on upper left square
On top it have 1 on right 2 on bottom 4 and on left 8
IF for example there is track on left and above it you would get 9 in variable
Since there is 8 on left and 1 on top

If there is track on top and bottom from newly placed track you get 5
Since on top there is 1 and on bottom is 4

And so go on
You could make dummy animations you do not care about
And simply add to newly placed track based on adjacent tracks

1 Like

i love that idea ! thank a lot for that graph !


i’m trying that way to check if my “token” collide with a newsprite (it would be my tracker) but doesn’t work.

This way it does.
When placing my tracker sould i swap between 2 different one ? maybe i’m doing it the wrong way.
I will for sure use your 1-2-4-8 for replacing track by true object.
the true block will be only placed once, on a button click. so i don’t need it to update in real time.

My problem remain, that i need to check 2 indic side by side, and they are the same Object and it seem to not working.

If i get your exemple right, you check on the point of blue is inside the red.
i need to check if the point of blue is inside blue, and this seem to be not working.

Look at my screenshot


I am tinting blue pieces to well blue
You should tint each object from whatever position its coming from to see what is going on

Look here


On the right i could tint each blue piece to different color to see if it is detecting them properly
Also notice that i am checking for each for red
And in condition i check if point from red is inside blue not if point of blue is inside red

I DO NOT know what is correct order i just switch stuff around until it works
BUT assuming from my screenshot i would say you check for each event for tracks + check if point from tracks is inside indicator and pass that info / change variable of placed indicator object
Maybe you should check for indicator object in for each
Check if indicator objects point is inside tracks so you do it other way around
BUT for sure you should tint them to see what is detecting what and IF its detecting anything
DO NOT believe what you see in events but make your own system of checking if something you want to happen is actually happening

Like i said key factor here is to rearrange objects around in event

On 1st screenshot in this post i only wanted a way to detect something
2nd screenshot detects what i want exactly
That is why for one order is checking blue in for each and then point of blue inside red
Where in 2nd screenshot i check for each red and if red point is inside blue

I do not care to understand it i do not care to know it i can tint that objects and see am i getting result i want
Trying to understand it makes my head hurt
I suggest you try same approach

On top of that i would ditch linking since you do not need it here
Go fully with variables
One variable to set animation other variable to check if animation of track was already changed
So one var would be number var to set animation
While other could be boolean

i quickly set up that.

Using your maths side method, is work great and from there, i can setup everything as i want.

My only remaining problem is still the same.
It’s the cheking part, i can’t make it work, to check if black block collide with black block, i can only test collide with different sprite.

I’m so happy with the result.
Pathing

Here is the checking part to take information of what is around .

Here i add all value (don’t forget to set up 0 at strat or it will rise up)

Here are the treatment of each value.

all of that was made with this. ( ZeroX4 send it me)
image

2 Likes