1
Technical forum / Moving non-actor entities towards an XY position
« on: March 01, 2012, 09:26:39 AM »
Hi all,
I have a puzzle set up with a few objects (entities) and hotspots (regional entities). When you click on an object, I enable the vacant hotspots that the object can move in to.
Instead of simply skipping to the new location, I would like the objects to "slide" over to the new XY positions. I need something similar to the GoTo method for actors, but for entities.
I tried the following, but the object doesn't move smoothly a straight path, which I can understand why is happening. (It's reaching it's new X position before the Y position, or vice versa)
To explain the code:
EyesActivePiece = the puzzle piece that needs to move
this = the hotspot you click on that contains the object's new XY coordinates
cpX and cpY = the hardcoded X and Y coordinates of the hotspot that the object must move towards
I really appreciate your help. Thanks!
I have a puzzle set up with a few objects (entities) and hotspots (regional entities). When you click on an object, I enable the vacant hotspots that the object can move in to.
Instead of simply skipping to the new location, I would like the objects to "slide" over to the new XY positions. I need something similar to the GoTo method for actors, but for entities.
I tried the following, but the object doesn't move smoothly a straight path, which I can understand why is happening. (It's reaching it's new X position before the Y position, or vice versa)
To explain the code:
EyesActivePiece = the puzzle piece that needs to move
this = the hotspot you click on that contains the object's new XY coordinates
cpX and cpY = the hardcoded X and Y coordinates of the hotspot that the object must move towards
I really appreciate your help. Thanks!
Code: [Select]
var moving = true;
while (moving)
{
if (this.cpX > EyesActivePiece.X)
EyesActivePiece.X = EyesActivePiece.X + 1;
else
EyesActivePiece.X = EyesActivePiece.X - 1;
if (this.cpY > EyesActivePiece.Y)
EyesActivePiece.Y = EyesActivePiece.Y + 1;
else
EyesActivePiece.Y = EyesActivePiece.Y - 1;
if ((EyesActivePiece.X == this.cpX) && (EyesActivePiece.Y == this.cpY))
moving = false;
Sleep(5);
}