Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Glenjamin on Mon 20/04/2015 03:19:15

Title: The monsters comin to get ya!
Post by: Glenjamin on Mon 20/04/2015 03:19:15
Hello everyone! I'm woeking on a game where you get chased by a monster. When the monster touches you, you'll be teleported to a game over room.

I've been using this

Code (ags) Select

if (cmonster.IsCollidingWithChar(cEgo) == 1)
{cEgo.ChangeRoom(17,181, 105); }


However, it just doesn't work the way I need it to. I want the action to be dont instantly, but whenever the monster gets close to the player their sprites overlap and nothing happens. The code does work, because i've seen the player get teleported. It just doesn't work the way I want it to, if at all. Please help! Thank you!
Title: Re: The monsters comin to get ya!
Post by: MyEakinBack on Mon 20/04/2015 04:03:52
That function only works when the players feet are in exactly the same place. It sounds like you'll have to compute the distance between characters. Maybe something like this:


  float delta_x, delta_y, distance;
 
  delta_x = IntToFloat(cmonster.x) - IntToFloat(cEgo.x);
  delta_y = IntToFloat(cmonster.y) - IntToFloat(cEgo.y);
  distance = Maths.RaiseToPower((Maths.RaiseToPower(delta_x, 2.0) + Maths.RaiseToPower(delta_y, 2.0)), 0.5);
  if (distance < 30.0) cEgo.ChangeRoom(17, 181, 105);
Title: Re: The monsters comin to get ya!
Post by: Glenjamin on Mon 20/04/2015 04:30:02
Thank you so much! I put it in my script, but it still doesn't work. The characters just fumble over each other like they used to. Am I missing something? Is there a specific place this needs to go? Do I need to change anything? Thanks again.
Title: Re: The monsters comin to get ya!
Post by: Slasher on Mon 20/04/2015 05:44:22
For simplicity and ease you may at this point use the Tween module it's collide check is better in some cases. Check out plugins and module. It quite easy to use.






Title: Re: The monsters comin to get ya!
Post by: Monsieur OUXX on Mon 20/04/2015 09:28:45
MyEakinsBack's function is a good start, but I suspect there could be a second issue :

I think the second issue might be that the collision detection does work, but gets executed only after the characters finish walking.
Try adding a cmonster.StopWalking and cEgo.StopWalking in your collision script and see if it makes the teleportation immediate.
If the issue persists, please explain where you put the collision detection function: In repeatedly_execute, or in repeatedly_execute_always?