My game

Started by: sticky505 | Replies: 5 | Views: 682 | Closed

sticky505

Posts: 34
Joined: Sep 2008
Rep: 10

View Profile
Feb 14, 2009 7:00 PM #357321
I have made this game a little like call of duty: world at war please would someone tell me how I can make the crosshair move at the same time as the gun pointing to the crosshair but not moving from its place but pivoting on its bottom. I know how to make the crosshair follow the mouse using actionscript *_root.crosshair._x = _root._xmouse; and *_root.crosshair._y = _root._ymouse;* (See diagram): the gun is a MP40.
Paco
2

Posts: 910
Joined: Feb 2006
Rep: 10

View Profile
Feb 14, 2009 7:31 PM #357344
are you asking for the gun to follow the crossair on its x axis?
or rotate towards it?
Automaton
2

Posts: 4,779
Joined: Nov 2007
Rep: 10

View Profile
Feb 14, 2009 7:34 PM #357347
I think he means rotate. Generally in games the whole person moves not just the gun.
sticky505

Posts: 34
Joined: Sep 2008
Rep: 10

View Profile
Feb 14, 2009 11:13 PM #357533
I actually mean rotate..do you know how to?
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Feb 15, 2009 12:00 AM #357558
I used this in my old RPG engine;


//------------------------------
//Rotating to face the mouse
//------------------------------


//-------------
//Instructions
//-------------

//First draw the thing you want to point at the mouse. Convert it to a movie clip, making sure the regestration
//point is on the bit the pointer will pivit on. The name doesn't matter.
//Then double click it to go into it's seperate timeline. Draw somthing that is invisible (Or just the color of
//your background) and covert it to a symbol. Nothing in the coversion //process matters for this one so hit ok.
//Then enter this code in the invisible thing:

//-------
//Script:
//-------

onClipEvent (enterFrame) {
z=_root._xmouse-_parent._x;
r=_root._ymouse-_parent._y;
_root.a=z;
_root.b=r;
}
onClipEvent (enterFrame) {
e=z/r;
k=Math.atan (e);
}
onClipEvent (enterFrame) {
g=k*180/Math.PI;
_rotation=g;
if (_root._ymouse>_parent._y) {
_parent._rotation=90-_rotation;
} else if (_root._ymouse<_parent._y) {
_parent._rotation=180-(_rotation-90);
}
}

Done and done-er! The instructions I put in the code should be kept so you can check how this works without digging for the thread.

Note that this script will rotate it around the little circle you can see when using the transform tool
sticky505

Posts: 34
Joined: Sep 2008
Rep: 10

View Profile
Feb 15, 2009 4:39 PM #357917
kk thanks for you help