Rotate circle on mouse position

About advanced scenes, and the Thyme scripting language used in Algodoo.

Rotate circle on mouse position

Postby Luka » Sun Mar 22, 2015 10:09 pm

Got an idea to make a battleship with working guns and stuff. The only problem is that I can't understand completely what's going on in the automated mouse-controlled gun (the one made by pixartist). And I just want to activate the axle without changing the RPM.

Help will be helpful :lol:

EDIT - This is the thing which I want.
Attachments
Capture.PNG
(28.46 KiB) Not downloaded yet
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Luka
 
Posts: 17
Joined: Wed Oct 23, 2013 12:57 pm
Location: pos[0, 0]

Re: Rotate circle on mouse position

Postby Kilinich » Mon Mar 23, 2015 11:17 am

Simplest way is to set bend / bendTarget for turrel and connect it to +inf inertiaMultilpier circle.

Draw new circle on top of turret, hinge it to turret.

in circle ->
postStep = (e) => {scene.my.tpos = pos}
onSpawn = (e) => {scene.my.tpos = pos}
inertiaMultilpier = +inf

in bend hinge ->
bend = true;
bendTraget = {v := app.mousepos - scene.my.tpos; math.atan2(v(0),v(1))}
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Rotate circle on mouse position

Postby Luka » Mon Mar 23, 2015 5:57 pm

Worked. By the way the bendTarget was offset.
So I changed the atan2 part code and swapped 0 with 1 and 1 with 0 (that's how math calculates angle from 2 variables).
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Luka
 
Posts: 17
Joined: Wed Oct 23, 2013 12:57 pm
Location: pos[0, 0]

Re: Rotate circle on mouse position

Postby marinelee » Tue Mar 24, 2015 5:33 am

nice info Kilinich :thumbup:
User avatar
marinelee
 
Posts: 1
Joined: Tue Mar 24, 2015 5:16 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests

cron