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

yoplalala

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

LIBERADO

  • *
  • Posts: 2720
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: 1795
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: 2720
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: 1795
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: 2720
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: 1632
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: 2720
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: 2720
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: 488
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

Hey Liberado,

Awesome work with these tools! Really love your stuff.
If I may, would I be able to try out an extension which moves an actor along a bezier curve, rather than draw one?

Cheers,
JBG

LIBERADO

  • *
  • Posts: 2720
Sure.
   

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

Thank you so much!

JBG

Hell O

  • Posts: 10
Sure.
   

   
Here it is.

Hi Liberado, thank you so much for this extension! It is SO useful! I would like to know if there would be a way to use velocity/speed instead of "Over x Seconds" ? Thanks!

harshhsrah

  • Posts: 73
The tweening library in Stencyl has changed in the latest build ....any pointers on how to implement the bezier curves there?