The monsters comin to get ya!

Started by Glenjamin, Mon 20/04/2015 03:19:15

Previous topic - Next topic

Glenjamin

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

 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!

MyEakinBack

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:

Code: ags

  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);
completed: Beyond Eternity

Glenjamin

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.

Slasher

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.







Monsieur OUXX

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?
 

SMF spam blocked by CleanTalk