(Solved)Check if character and animation are overlapping

Started by Racoon, Mon 10/10/2022 20:13:08

Previous topic - Next topic

Racoon

Hi,

I am trying to implement something in my game, but I don´t really know how.

I have an animated object as some form of surveillance system and I want something to happen if the animation and the character are touching/overlapping. But this should not happen if the player is hiding behind an object.

To better show what I mean I made this Gif:



I was thinking of using IsCollidingWithObject or AreThingsOverlapping, but I don´t know how, so I was hoping maybe somebody here can help me get an idea of how it could work.

AndreasBlack

#1
Quote from: Racoon on Mon 10/10/2022 20:13:08Hi,

I am trying to implement something in my game, but I don´t really know how.

I have an animated object as some form of surveillance system and I want something to happen if the animation and the character are touching/overlapping. But this should not happen if the player is hiding behind an object.

To better show what I mean I made this Gif:



I was thinking of using IsCollidingWithObject or AreThingsOverlapping, but I don´t know how, so I was hoping maybe somebody here can help me get an idea of how it could work.

There is a perfect module for this you should take a look at Here: https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-pixel-perfect-collision-detection-v1-02/

It's really great for this kind of purpose, very easy to use!
You can check if a object(like that one) and a characters sprites are Pixelperfect colliding in repeatedly execute for the room in question, and that's it, if i remember correctly. So if he is behind another object and it does not reach, it would work without any additional coding! Can also check for characters colliding with each other

Looks great btw!


Khris

One way to solve this is using regions. Draw a region where the player gets caught for each frame of the animation, then check Region.GetAtRoomXY(player.x, player.y) against the current animation frame.

This way you can also easily implement the object the player can hide behind. Unless the object isn't static, in which case you could use some math to check the player position against the surveillance system's and object's coordinates.

Racoon

Thanks for your thoughts. Both ideas seem promising. I´ll try to make it work tomorrow :)

Racoon

So, I´m stuck again sadly.

I tried Khris approach, but the first problem I encountered is that the regions are overlapping and making a new region cuts the former region. So I tried to evade that with using a region, then a hotspot, then a region again and using  Region.GetAtRoomXY(player.x, player.y) and  Hotspot.GetAtRoomXY(player.x, player.y)worked.


But the character does not walk on a hotspot like on region, so I had to add
Code: ags
function hHotspot1_Interact()
{
player.Walk(mouse.x,  mouse.y, eNoBlock, eWalkableAreas);
}


But because it is a scrolling background it does not work like that in the extended side of the background and I found a thread where it is explained that you need to add the viewport to the mouse coordinates when you have a scrolling background with GetViewPortX() and GetViewPortY().

I tried:
Code: ags
function hHotspot1_Interact()
{
player.Walk(GetViewPortX()+ mouse.x,  GetViewPortY() + mouse.y, eNoBlock, eWalkableAreas);
}

but I get the error "undefined symbol GetViewPortY" every time. Am I using it in the wrong way?

Khris

If you're using the latest Version of AGS, Viewport functions have been replaced by the Camera system.
Try adding Game.Camera.X/Y instead.

However you can also use a third region for the overlapping part and adjust your region ID vs. surveillance frame code accordingly.

Snarky

Also, just a tip:

If you had searched the manual for GetViewportY you would have got three hits, including this.

Or if you had searched the forums for "undefined symbol GetViewportY" you would have got four hits, including this.

(And if that hadn't worked, you could have tried changing it to GetViewportX since those two functions are obviously closely related and any information about it might very likely apply to your problem.)

Racoon

Thanks a lot! Now it works.

Also thanks for the tip, I did search for "undefined symbol GetViewportY"(+ags), but with google and I oversaw that thread, next time I´ll definitly search the forum directly too.

And I also tried looking it up in the manual, but with "GetViewport" and "GetViewportY()", which both got no match.

Even if it does not seem like it, I really did try to find a solution on my own for hours before I posted because I did not want to bug anyone needlessly.

eri0o

Uhm... It's the parenthesis. I need to think if they make sense, but perhaps simply filtering them by default would be a proper fix for now. I will see if I can quickly adjust this and if not create an issue to deal with this later - at least in the online JS based search one.

Edit: added a commit in the manual, when a next version is pushed on the web version, it should ignore parentheses, brackets and like in the search bar.

SMF spam blocked by CleanTalk