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
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!
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);
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.
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.
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?