Disable interactions on x-axis

Post about the Flash World Construction Kit and the Alchemy port of Box2D.
pxblender
Posts: 3
Joined: Tue Aug 06, 2013 6:42 am

Disable interactions on x-axis

Postby pxblender » Tue Aug 13, 2013 7:58 am

Hi, I am trying to disable the movement of an object on x-axis. I try

Code: Select all

world.addEventListener(Event.ENTER_FRAME, loop);
function loop(evt:Event):void
{
   obj.x = 0;
   obj.syncTransform();
}


I need that the obj interact only on y-axis.
The problem is when I drag on the x-axis or try to rotate pressing a key, the object don't stay in x = 0.
When I release the obj, it returns to x = 0. How can I avoid this behavior?

Thanks.

IstvanOrosi
Posts: 172
Joined: Thu Mar 01, 2012 9:31 am

Re: Disable interactions on x-axis

Postby IstvanOrosi » Tue Aug 13, 2013 10:51 am

I wonder if it makes a difference that you are using Event.ENTER_FRAME instead of the box2d/WCK StepEvent.STEP.

I haven't looked much into it but in one case instead of using syncTransform,
obj.b2body.SetTransform(new V2(new_x/world.scale, new_y/world.scale), 0);
seemed to work.

Update:
Another idea. Depending on your project, you could create a physical wall (and perhaps another one on the other side) that the object cannot go through. This should constrain the movement.


Return to “WCK”



Who is online

Users browsing this forum: No registered users and 1 guest