Create Joint Block

Gryffo

  • Posts: 11
Hello! I'd like to suggest blocks for design mode that would allow us to create joints during runtime.

The way I see it, there's little use for joints if you can only create them during authoring time (which is  what we have at the moment with the scene editor as far as I know). It is useful for some prebuilt contraptions, a rope/chain/bridge for instance, indeed.

Buuut, I think the real power of joints comes when you're able to create them at any given moment, like having your character able to grab a ledge, or remove a joint that existed so far, like breaking the aforementioned bridge.

I think that's it, thanks for reading and please inform me if I haven't been clear enough/at all.
If I have overlooked any feature of our current build 1.4.1 on this matter, please let me know :D
If we already DO have this ability, then don't tell any of your friends I ever asked.

Miasmos Games

  • Posts: 878
It can be done through code, but I know for a fact that Joint blocks are planned for some (hopefully close) future release.

Cupcake Bounce

Jon

  • *
  • Posts: 17524
We plan to add block support for joints in one of the 2.x releases - it's all part of a grander and planned out roadmap that we'll share around the time that we launch 2.0 - everything has a time and place in this roadmap. ;)

Gryffo

  • Posts: 11
That's great! Really looking forward to this feature and the others to be revealed in this roadmap.

As for now, if anyone happens to be willing to share code to customblock this feature, It'd be epic.
I've done joints before in pure Box2d, but the idea of 'everything tied to flixel' scares me to death.
Plus, the modifications stencyl has made to its version of the Box2d engine further drive me into a corner.

Thanks for the swift replies, guys!

Miasmos Games

  • Posts: 878
Hopefully 8BitWit or captaincomic will notice this thread, as I believe both have significant joint coding experience. If they don't appear here in a day or two try PMing them.

Cupcake Bounce

captaincomic

  • *
  • Posts: 6108
*Alright, alright, I'm coming...* ;)

What kind of joints do you need?
I uploaded my custom blocks on StencylForge, the behavior is called Joint Blocks.
It contains blocks to create Revolute Joints and Mouse Joints, but I guess creating the other joints won't be much different. There's also a block to destroy them and to modify the parameters.

Here's an example on how to use them:

Gryffo

  • Posts: 11
Okay, I havent been around for long, but I gotta say, hands down to this community. Captaincomic for one has already come to my aid more than once, and I dont even have 10 posts yet lol.

Thanks captain for the blocks, I'll be looking at them in a moment (just thought I'd say thanks before I did so) Also thanks for the 'bump' and the tips Miasmos, and thanks to Jon for being so active on the community. :D

captaincomic

  • *
  • Posts: 6108
Glad to help. And yes, this community is great :)

ffcurry

  • Posts: 29
I just want to say that I am looking forward to this block as well.  I was just looking for a way to add a joint dynamically.  This would add a huge amount of functionality to stencyl, I believe.


davient

  • Posts: 5
*Alright, alright, I'm coming...* ;)

What kind of joints do you need?
I uploaded my custom blocks on StencylForge, the behavior is called Joint Blocks.
It contains blocks to create Revolute Joints and Mouse Joints, but I guess creating the other joints won't be much different. There's also a block to destroy them and to modify the parameters.

Here's an example on how to use them:

I'm trying to use your code to add a revolute joint when two Actors collide.  (really I want a fixed joint, but that should be simple to change once I get the basics done :)

From the log it looks like I'm using this on something that has not been initialized. Any pointers on debugging this?

Dave

Hectate

  • *
  • Posts: 4643
Did you completely customize the behavior when attaching it to the scene or actor? What exactly is on line 50 in code preview?
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

davient

  • Posts: 5
I think I have fully customized the block. I assume you mean selecting the correct variables by dragging them across or otherwise.

Testing by removing these values, leads to clear null pointer exceptions.

The code for the custom joint block function (by captaincomic) is:

Code: [Select]
42 /* Params are:__actor1 __x1 __y1 __actor2 __x2 __y2 __this */
43 public static function CreateRevoluteJoint(__actor1:Actor, __x1:Number, __y1:Number, __actor2:Actor, __x2:Number, __y2:Number, __this:Object):void
44 {
45       __x1 = GameState.toPhysicalUnits(__x1);
46       __y1 = GameState.toPhysicalUnits(__y1);
47       __x2 = GameState.toPhysicalUnits(__x2);
48       __y2 = GameState.toPhysicalUnits(__y2);
49       b2Def.revoluteJoint.Initialize(__actor1.getBody(), __actor2.getBody(), new V2(__x1, __y1));
50       var joint:b2RevoluteJoint = __this.scene.world.CreateJoint(b2Def.revoluteJoint);
51       joint.m_localAnchor1.x = __x1;
52       joint.m_localAnchor1.y = __y1;
53       joint.m_localAnchor2.x = __x2;
54       joint.m_localAnchor2.y = __y2;
55       __this.lastCreatedJoint = joint;
56  }


davient

  • Posts: 5
Further investigation leads me to see that this only occurs when the code is called from a Collision event.

So in my attached example: enabling the revolute joint "when created" block, will successfully create a revolute joint with Blok2 at 50,50.

However, disabling this block and enabling either of the collision blocks results in the same error as error shown above (TypeError: Error #1010: A term is undefined and has no properties.
   at scripts::Design_6_6_JointBlocks$/CreateRevoluteJoint()[C:\Users\Dave Cooper\AppData\Roaming\Stencyl\stencylworks\preview\scripts\Design_6_6_JointBlocks.as:50])


Hectate

  • *
  • Posts: 4643
Ah, then the likely culprit is the code block containing "this". The collision blocks probably don't have anything that defines what "this" is to the compiler. So what exactly should be referenced instead? Maybe try "self" instead for the collision ones?

I'm not sure what kind of Object is being referenced but it looks like it's being used to get to the scene overall in the custom code.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

davient

  • Posts: 5
Thank you for the nudge in the right direction :)

Indeed it has everything to do with what "this" references. A simple "this.toString()" for within the creation and the collision code yields the difference. The creation code runs with "this" being an instance of "ActorEvents 0", which as is required, has an attribute scene, which allows the code to run fine.

However, where the collision code runs  "this" represents an "[object global]" which has no clear way I can find to access the scene property. So I've whipped up a simple workaround.
Simply set an attribute to the actor that has been collided. Then activate an event. In that custom event you can call the revolute joint code referencing "this" without any problems.

See attached for my example:

Note: I've had to switch the coordinates of Self and the Colliding Actor to get the joint to be in the correct place. This was not an expected need and may help others :)