[Behavior] moveto

Post your completed addons to share with the community

Post » Fri Mar 21, 2014 8:22 am

punkineo wrote:I'm sorry, I don't mean to bump this topic (if that's bad), but this plugin is absolutely amazing. Thank you for taking the time to create it!


I agree totally ;)
B
15
S
5
G
2
Posts: 167
Reputation: 2,009

Post » Mon Apr 21, 2014 6:57 am

For all who are interested:

I am writing a shoot-em-up game and I needed to design flight patterns for my enemy ships. It's kind of like a waypoint system where they would move into the play area past the top of the screen, moveto point A, moveto point B, moveto point C etc... until it moves to outside the screen again past the bottom.

However, the moveto plugin kept on triggering true on the condition "On MoveTo Hit Target", which is what I didn't want. So I made a small modification on line 105 of runtime.js:

Instead of this:
Code: Select all
if ( (this.remain_distance <= 0) || (this.current_speed <= 0) )


it's now:
Code: Select all
if (this.remain_distance <= 0)


I sure don't need "current_speed <= 0" to be true. Just wanted to share is all... it might help those who want such a waypoint feature.

Or maybe it's an error? Not sure, that's for @rexrainbow to comment.
=========================================
If you are on Linkedin, join other C2 professionals and network on the Scirra Construct 2 Developer Group at https://www.linkedin.com/groups?home=&gid=6732005
B
47
S
10
G
6
Posts: 193
Reputation: 7,584

Post » Fri Apr 25, 2014 4:12 pm

For those who want to be able to debug the Moveto behavior, add the code copied from the box below at around line 215 of runtime.js... just before the comment that says "Conditions".
this._moving_angle_info = o["ma"];
this._last_tick = o["lt"];
};
>>>>>ADD DEBUG CODE HERE
//////////////////////////////////////
// Conditions


Copy and paste this debug code into runtime.js of the moveto behavior
Code: Select all
   /**BEGIN-PREVIEWONLY**/
   behinstProto.getDebuggerValues = function (propsections)
   {
      propsections.push({
         "title": this.type.name,
         "properties": [
            {"name": "Target X", "value": this.target["x"]},
            {"name": "Target Y", "value": this.target["y"]},
            {"name": "Current speed", "value": this.current_speed},
            {"name": "Remaining distance", "value": this.remain_distance},
            {"name": "Hit target", "value": this.is_hit_target, "readonly": true},
         ]
      });
   };
      
   behinstProto.onDebugValueEdited = function (header, name, value)
   {
      var a, s;
      
      switch (name) {
      case "Target X": this.target["x"] = value; break;
      case "Target Y": this.target["y"] = value; break;
      case "Current speed": this.current_speed = value; break;
      case "Remaining distance": this.remain_distance = value; break;
      }
   };
   /**END-PREVIEWONLY**/


This has not been fully tested (watch/edit), so use at your own risk.
=========================================
If you are on Linkedin, join other C2 professionals and network on the Scirra Construct 2 Developer Group at https://www.linkedin.com/groups?home=&gid=6732005
B
47
S
10
G
6
Posts: 193
Reputation: 7,584

Post » Sat Apr 26, 2014 12:52 am

@necromaster

Thanks, I had merged this code into my plugin and updated it.
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Sat Apr 26, 2014 2:20 am

Great!

Thanks.
=========================================
If you are on Linkedin, join other C2 professionals and network on the Scirra Construct 2 Developer Group at https://www.linkedin.com/groups?home=&gid=6732005
B
47
S
10
G
6
Posts: 193
Reputation: 7,584

Post » Sat Apr 26, 2014 7:49 am

@rexrainbow

Rex, occasionally the trigger "On MoveTo HIT TARGET" is triggered even when the X,Y Position of the object is different from the target.
(I'm using the latest MoveTo plugin you posted on 1st page & Construct r168)

The screenshot and the capx to repro the bug is on attachment.
Try to click Area A & B back and forth really quick several times to repro it, then check the console afterward ;)
btw, thanks again for this awesome plugin.
You do not have the required permissions to view the files attached to this post.
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Sat Apr 26, 2014 9:14 am

Update

Fix bug found by Potato


@Potato

Thanks, it really need to set the target position at a very special tick.
The concept of triggering "On MoveTo HIT TARGET" is that -
the moveTo behavior set the instance to target position, it means that this instance try to move from current position to target position.
And the "On MoveTo HIT TARGET" will be triggered next tick since the instance has already at target position.

If the target had been changed between these two ticks at event sheet, it will cause the bug. So I check the target position again before "On MoveTo HIT TARGET" triggered.
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Sat Apr 26, 2014 9:31 am

Thanks for fixing it rex, the update so far works great.
You're the best :D
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Mon May 19, 2014 11:05 am

Nice behavior, thanks !

I hope you will make behavior: ZoomTo or SizeTo on the same model ;)
B
12
S
2
Posts: 60
Reputation: 1,592

Post » Mon May 19, 2014 11:08 am

@amkp

Try tween behavior
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 1 guest