Is it at all possible to alter or change in any way the position of the mouse??
I am working on a shooting game, and in the parts of the game where you have a sniper rifle and a scope I would like to make it so that when you shoot you get some form of recoil.
not really, you can have the mouse control an MC cursor on the screen and offset that, but before you know it, the cursor is in the corner of the screen and another sniper blows your face off:)
You cant affect mouse position… altought you can create your own cursor and dont case about mouse position itself…
In your case you could apply that recoil without caring about mouse position… just set it as a value which adds or substracts from mouse position and thus affects aiming…
I tried changing the _x and _y values, but the thing is that the _x and _y values are updated every frame, so when it moves, it immediately goes back to the cursor.
That code right there alters the position, but because of the function scopeposition, it goes RIGHT back to here it was before firing. I’ll upload the fla
EDIT: File limit reached, anyone know where I can host my FLA if it goes over the 73 kb limit?
on the main timeline put a variable (call isRecoil) make it a boolean and set it to false
then add
scopeposition = function() {
if(!isRecoil){
this._x = _root._xmouse
this._y = _root._ymouse
updateAfterEvent();}
you just have to figure out how you want to lose recoil
eventually youll want a isRecoil = false(and then it will track to the mouse again)
maybe put an else in the on enterframe the positions this._x,_y to closer and closer to the actual mouse each onEnter and once its back on the mouse set isRecoil to False
basically you have to put in very rigid rules for the gun to follow
obviously(at least with a real gun) after a gun recoils it doesnt stay recoiled
a beter way to do it would prolly to make an on mouse move that tracks the mouse movement(ANGLE and DISTANCE)and moves the pseudo pointer the same angle/Distance)
heh im pretty new to AS myself…!isRecoil is the same as isRecoil == false
! in front just means not
so its if(not isRecoil){}
see the thread about angles to figure out the angle for 2 points than just have a mouseOnMove function
that does
Mouse.onMove = function(){
var currentPos:Object = {x:_xmouse, y:_ymouse)
//getAngle and distance between currentPos and oldPos
//Move PseudoMouse same angle and distance as mouse
oldPos = currentPos
}
try playing with it as much as you can if you cant get it to work post what you have and ill try and help
[edit]
thread with explanation of the formula to find angle here http://www.kirupa.com/forum/showthread.php?t=216680