what's the best way to get an actor to follow a bezier curve?

SadiQ

  • Posts: 1769
Dooh....I tried that one but failed to initialize tweenLoc like you did, so my test failed.
 I knew it was some silly mistake of mine :(
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

yoplalala

  • *
  • Posts: 1456
:( it happens to the best

LIBERADO

  • *
  • Posts: 2568
Thanks to your help I have made an extension:
   
<a href="http://static.stencyl.com/games/37954-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/37954-0.swf</a>
   
I really need beautiful bezier curves because I was tired of sliding actors in boring straight lines only.

« Last Edit: December 10, 2017, 10:48:02 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

SadiQ

  • Posts: 1769
Hehe. Cool example mate.
I added a pull request before yoplala solved this issue to integrate bezier movement of actors directly into the engine, so if it gets accepted it will be in the beta version of stencyl :)

P.S. This example would definitely work as a scene transition with some tweaks :)
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

LIBERADO

  • *
  • Posts: 2568
I added a pull request before yoplala solved this issue to integrate bezier movement of actors directly into the engine, so if it gets accepted it will be in the beta version of stencyl :)
That would be fantastic.

By the way, with the default formula the actor never reaches the control point. This does not seem suitable to me. I have added some maths to get the actor to always reach the control point, so I can have a better control of its position.

I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

SadiQ

  • Posts: 1769
Wow...that's actually better than the original. If it makes it in the engine we'll have to update it to use your code :) (if you don't mind sharing it)
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

LIBERADO

  • *
  • Posts: 2568
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

yoplalala

  • *
  • Posts: 1456
Nice example ;). Makes me want to use this extension.
What is your modified formula  ?:)

Looking at the Actuate MotionPath ... It is really is interesting.  You can actually make a path from multiple lines and bezier curves ( nothing else sadly).

LIBERADO

  • *
  • Posts: 2568
My formula:
Code: [Select]
class MoveAlongBezierCurve {

public static function moveAlongBezierCurve( a:Actor, x2:Float, y2:Float, cx:Float, cy:Float, t:Float, e:motion.easing.IEasing) {
var x1:Float;
var y1:Float;
var tempX:Float;
var tempY:Float;
var tempCX:Float;
var tempCY:Float;
x1 = a.getX();
y1 = a.getY();
tempX = Math.round(((x1 + x2) / 2));
tempY = Math.round(((y1 + y2) / 2));
tempCX = (tempX + ((cx - tempX) * 2));
tempCY = (tempY + ((cy - tempY) * 2));
a.activePositionTweens++;
a.tweenLoc.x = a.getX(false);
a.tweenLoc.y = a.getY(false);
var path = new MotionPath().bezier (x2, y2, tempCX, tempCY);
Actuate.motionPath (a.tweenLoc, t, { x: path.x, y: path.y }).ease(e).onComplete(a.onTweenPositionComplete);
}
}
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

LIBERADO

  • *
  • Posts: 2568
The test of my formula:
   
<a href="http://static.stencyl.com/games/37966-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/37966-0.swf</a>
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

bonzero

  • *
  • Posts: 487
Thanks a lot Liberado, I tried the code (superuseful it is), in order to make it work inside a custom code block I changed "new MotionPath" to "new motion.MotionPath (thanks Rob1221 & Justin) otherwise it wouldn't let me run the app