How to detect angles in wck

Post about the Flash World Construction Kit and the Alchemy port of Box2D.
jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

How to detect angles in wck

Postby jinisner » Mon Jun 10, 2013 11:55 pm

Hi,

I am in a situation where i need to perform some task when the object rotates by certain degrees , say if it rotates by 90 some stuff should happen, how can i detect an objects angle of rotation, i have no clue how to do it else i would have posted some code as to what i am trying , but i need your guidance ...

Thanks again ...

Regards
Jin

jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Re: How to detect angles in wck

Postby jinisner » Wed Jun 12, 2013 8:19 pm

Hi, can any one guide me as to how i can constantly find the angle of an object(like finding the coordinates of a mouse pointer as it moves on stage) while it is moving in wck world , may be then i can find it it has rotated by say 360 or 180 degree and then perform what i want ...

Thanks again ...

Regards
Jin

jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Re: How to detect angles in wck

Postby jinisner » Wed Jun 19, 2013 11:36 pm

Hi,

I came across this useful thread - http://www.iforce2d.net/b2dtut/rotate-to-angle


but when i try to use say world1.object1.GetAngle(); - i get error

when i use world1.object1.angle; - i get undefined value .... where am i going wrong ...

Regards

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

Re: How to detect angles in wck

Postby IstvanOrosi » Tue Jul 02, 2013 4:34 pm

Have you tried checking the 'rotation' property (e.g. world1.object1.rotation)? If I remember correctly, GetAngle() is used for b2body.

jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Re: How to detect angles in wck

Postby jinisner » Wed Jul 03, 2013 12:19 am

@Istvan - thanks a lot ...

I will give it a try and post back

Regards
Jin

jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Re: How to detect angles in wck

Postby jinisner » Wed Jul 03, 2013 5:04 am

Hi @istvan,

I tried like this -

var rot =level1WorldObj.car.rotation;
trace(rot);
if(rot>170)
{
trace("front flip");
}

else if(rot < -170)
{
trace("back flip");
}

but some time it gives backflip some times for same motion frontflip and if object moves too fast ...no value ....

Thanks in advance ...

Regards
Jin

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

Re: How to detect angles in wck

Postby IstvanOrosi » Wed Jul 03, 2013 11:49 am

When you trace 'rot', what kind of values do you get? Is it perhaps between 180 and -180?

To keep track of continuous rotation in one direction, it may be better to use your own variable for rotation.

jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Re: How to detect angles in wck

Postby jinisner » Sun Jul 07, 2013 7:27 am

@Istvan - thanks a lot , sorry for the late response,, i was out of town for some time, i will try that tomorrow and let you know ....

Thanks again ...

Regards
Jin

jinisner
Posts: 146
Joined: Tue Apr 17, 2012 12:08 am

Re: How to detect angles in wck

Postby jinisner » Tue Jul 09, 2013 6:10 am

@Istvan , i am trying to use the below code -

var rot:Number =level1WorldObj.car.rotation;

//trace(rot);
if(rot > 175)
{
trace("front flip");

}

if(rot < -175)
{
trace("back flip");

}

i also tried using else if , but i always get wrong trace output , like if i frontflip the car it shows backflip and vice versa and some other times the right value ...

A bit confused , hope you can guide me ...

Thanks again

Regards
Jin

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

Re: How to detect angles in wck

Postby IstvanOrosi » Fri Jul 12, 2013 10:43 am

If I remember correctly, object rotation values will be between 180 and -180, so your current code will not be able to do what you want. That's why you have to use your own rotation variable and keep track if the object has rotated more than 180 (or -180)


Return to “WCK”



Who is online

Users browsing this forum: No registered users and 1 guest