Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-22-2008, 09:49 PM   #1
insanepolak
Registered User
 
Join Date: Mar 2008
Posts: 28
Default Create something like Tilt2

I'm trying to make something like Tilt2.

I've got it to tilt moving left and right with the mouse.
But I'm having trouble getting it to tilt and at the same time move with the mouse.

Am I thinking the right way?
Any help would be great
Attached Files
File Type: zip tilt.zip (5.5 KB, 57 views)
insanepolak is offline   Reply With Quote
Old 07-23-2008, 05:14 PM   #2
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

Two things you'll want to learn about:
Math.atan2(y,x)
Inverse Kinematics
rrh is offline   Reply With Quote
Old 07-23-2008, 07:02 PM   #3
insanepolak
Registered User
 
Join Date: Mar 2008
Posts: 28
Default

Alright so I did some research and got something working.
ActionScript Code:
move = function () {     this._x = _xmouse;     this._y = _ymouse;     var distance_x = stick._x-this._x;     var distance_y = stick._y-this._y;     var alpha = Math.atan2(distance_y, distance_x);     stick._x = this._x+Math.cos(alpha)*totalDistance;     stick._y = this._y+Math.sin(alpha)*totalDistance;     stick._rotation = (Math.PI+alpha)*180/Math.PI;     trace(stick._rotation);     }; press = function () {     this.onMouseMove = move; }; release = function () {     delete this.onMouseMove; }; var totalDistance = 170; ball.onPress = press; ball.onRelease = release; ball.onReleaseOutside = release; ball.move = move;

Now I'm trying to get the stick to rotate around the ball until it points down, but I'm having trouble making a loop to rotate properly around the ball.

I tried to make the rotation point the origin of the stick at 0,0 but then the totalDistance is 0 which screws up the move function rotation.
insanepolak is offline   Reply With Quote
Old 07-23-2008, 07:18 PM   #4
insanepolak
Registered User
 
Join Date: Mar 2008
Posts: 28
Default

now I've made the ball the mouse, still trying to get the "balance" aspect working..

ActionScript Code:
onEnterFrame = function() {     ball._x = _xmouse;     ball._y = _ymouse;     ball.onMouseMove = move }; move = function () {     var totalDistance = 170;     this._x = _xmouse;     this._y = _ymouse;     var distance_x = stick._x-this._x;     var distance_y = stick._y-this._y;     var alpha = Math.atan2(distance_y, distance_x);     stick._x = this._x+Math.cos(alpha)*totalDistance;     stick._y = this._y+Math.sin(alpha)*totalDistance;     stick._rotation = (Math.PI+alpha)*180/Math.PI; }; var totalDistance = 170; ball.move = move;
insanepolak is offline   Reply With Quote
Old 07-24-2008, 03:04 PM   #5
newblack
dondeEstanMisPantalones?
 
newblack's Avatar
 
Join Date: Nov 2005
Location: New York Proper
Posts: 1,355
Send a message via AIM to newblack
Default

i don't really like the end goal (tilt2)... i think that what makes it fun is the physics and they're at best crap. you could use a physics engine like box2d or try to write the equations of motion yourself. depending on how geeky you are the latter could be either horrible or fun.
__________________
i am gibreel farishta
general relativity
jellytanks alpha redux
newblack is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
applicationStorageDirectory xwielder AIR (Apollo) 1 09-14-2007 08:17 AM
Create onrollOver event without onrollOver AS mcrodrigues ActionScript 2.0 1 06-02-2007 03:25 AM
Can you create rollover events on CheckBoxes in AS2.0? sadbuttrue ActionScript 2.0 1 02-20-2005 08:18 PM
how do i create a mc with a button inside? nettemor ActionScript 2.0 4 11-30-2004 02:32 PM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM


All times are GMT. The time now is 10:04 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.