Stencyl 3.4.0 is now out. Get it now!

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

designpeg

  • *
  • Posts: 541
Any one got a simple way to get  an actor to follow a bezier curve from a list of point?

I've played around with Actuate.motionPath but with no luck - I've looked at other peoples suggestions, but my app doesn't compile, and I get an  "Type not found : MotionPath" error

JeffreyDriver

  • Posts: 1358
Surely there's a pure mathematic solution to this?

What exactly are you trying to achieve? Maybe you can fake it somehow?


designpeg

  • *
  • Posts: 541
Hi greatanthony, i'd seen that post, but am not sure how to implement it. Were does the public function go?

greatanthony

  • Posts: 132
hi,
if all the code logic is understood and only public function is the problem then it should not be hard...

Public function was throwing error b'cause the code is already added to a Event ( or a public function )....

In any event Add the [Code ] block and add the code below to it...
Code: [Select]
tweenLoc.x = getX(false);
tweenLoc.y = getY(false);

if(easing == null)
{
easing = Linear.easeNone;
}

activePositionTweens++;
var path = new MotionPath().bezier(x, y, checkPointX, checkPointY ,strength);
Actuate.motionPath(tweenLoc, duration, { x:path.x, y:path.y }, false ).ease(easing).onComplete(onTweenPositionComplete);

Put own number inputs in input place like (x , y , strength)  in the code...
Am typing on mobile, sorry for any typo, let know about progress.....

Anthony

« Last Edit: July 17, 2017, 08:56:35 am by greatanthony »

SadiQ

  • Posts: 1755
Add a custom import in your actor behavior and add this into it:
Code: [Select]
import motion.MotionPath;

After that add the following code in a different event (like a click event or something that's not the Always or Draw event)
Code: [Select]
var path = new MotionPath().bezier (100, 100, 50, 50);
Actuate.motionPath (actor, 2, { x: path.x, y: path.y });

That will make your actor move from it's current position to 100,100 using 50,50 as control points. You can replace those numbers to match your curve points.
The 2 in the second line is the time that the actor will take to reach the target you want.
You can even add a strength to the motion path to tweak how strict the player follows that path should you need to.
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

greatanthony

  • Posts: 132
works great!!  :)

designpeg

  • *
  • Posts: 541
Thanks SadiQ, the import motion.MotionPath; was the bit i'd missed.

LIBERADO

  • *
  • Posts: 2507
@SadiQ, there is an important inconvenience when using your code: while the actor is moving, and even when the tween has finished, the actor coordinates are not updated.

Do you know how to solve this? Please.
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: 1755
I did a quick test before I leave the house. It seems the collision box doesn't move with the actor(I'll test more when I get back home).
In the mean time you can try this:
Code: [Select]
var path = new MotionPath().bezier (100, 300, 50, 50);
for(actorOfType in getActorsOfType(getActorType(8))) //my test actor
{
if (actorOfType != null && !actorOfType.dead && !actorOfType.recycled) {
var obj = { X:actorOfType.x, Y:actorOfType.y };
Actuate.motionPath(obj, 2, { X:path.x, Y:path.y }, true ).onUpdate(function() { actorOfType.setX(obj.X); actorOfType.setY(obj.Y); } );
}
}
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

LIBERADO

  • *
  • Posts: 2507
Now, your new code causes this error:

Events for 'Scene': For expression should be 'v in expr'
   from scripts.SceneEvents_0
   line: 123
   columns: 4-11


Then, if I remove the "for(......)" line, the tween works incorrectly, causing these two issues:

- The actor position is suddenly changed just before it starts moving. (half of its width and half of its height)
- Also, strangely, I get the #1009 error if I reload the scene while the tween is running:
Code: [Select]
TypeError: Error #1009: No se puede acceder a una propiedad o a un m├ętodo de una referencia a un objeto nulo.
at com.stencyl.models::Actor/setX()[C:/Program Files (x86)/Stencyl_v34_B9328/plaf/haxe/lib/stencyl/1,00/com/stencyl/models/Actor.hx:2556]
at MethodInfo-6344()[Source/scripts/SceneEvents_0.hx:127]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at Function/<anonymous>()
at motion.actuators::GenericActuator/change()[C:/Program Files (x86)/Stencyl_v34_B9328/plaf/haxe/lib/actuate/1,8,6/motion/actuators/GenericActuator.hx:140]
at motion.actuators::MotionPathActuator/update()[C:/Program Files (x86)/Stencyl_v34_B9328/plaf/haxe/lib/actuate/1,8,6/motion/actuators/MotionPathActuator.hx:225]
at motion.actuators::SimpleActuator$/stage_onEnterFrame()[C:/Program Files (x86)/Stencyl_v34_B9328/plaf/haxe/lib/actuate/1,8,6/motion/actuators/SimpleActuator.hx:579]
at com.stencyl::Engine/update()[C:/Program Files (x86)/Stencyl_v34_B9328/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2324]
at com.stencyl::Engine/postUpdate()[C:/Program Files (x86)/Stencyl_v34_B9328/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2619]
at com.stencyl::Engine/onUpdate()[C:/Program Files (x86)/Stencyl_v34_B9328/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2595]
Sorry, I don't have much idea about Haxe code, so I hope you can solve these issues.

« Last Edit: December 09, 2017, 04:04:22 am 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: 1755
Can you post the code you're using?
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

LIBERADO

  • *
  • Posts: 2507
The actor is previously stored in the attribute called TARGET
   


I removed the "for(_TARGET)" code line to avoid the "For expression should be 'v in expr'" error message.

   

« Last Edit: December 09, 2017, 08:03:08 am 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: 1755
I'll have to call it quits on this one for now. I tested things all afternoon yesterday without any results :(
It seems the .onUpdate(function() { actorOfType.setX(obj.X); actorOfType.setY(obj.Y); } ) part doesn't get cancelled when the scene changes and I haven't found a way to work around the issue (and no ...checking if the scene is transitioning doesn't solve the issue).
If someone else can test this I'd learn something new from this problem.
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

yoplalala

  • *
  • Posts: 1435
You have to inspire yourself of Stencyl, which has already solved the case for you ;)
They're using an attribute tweenLoc to take care of our problems :)
https://github.com/Stencyl/stencyl-engine/blob/0e67a519288eefdd6eaddb4f0989db7fab026932/com/stencyl/models/Actor.hx#L3589

Solution

Replace _actor by your actor
you can change the ease ( stron ing, bounce in these kind of things) look at the code of a block using the ease to find the name you want
Code: [Select]
_actor.activePositionTweens++;
_actor.tweenLoc.x = _actor.getX(false);
_actor.tweenLoc.y = _actor.getY(false);
var path = new MotionPath().bezier (100, 300, 50, 50);
Actuate.motionPath (_actor.tweenLoc, 10, { x: path.x, y: path.y }).onComplete(_actor.onTweenPositionComplete).ease(Quad.easeInOut);

Reloading and collisions work

« Last Edit: December 10, 2017, 02:38:33 am by yoplalala »