_xmouse and _ymouse manipulation

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.

Any help at all would be schweet.

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.

you need to assign them “onEnterFrame”, then they will be updated every frame of the movie.

Can’t you just run liek:

my_crosshair._x = _root._xmouse + 50;
my_crosshair._y = _root._ymouse + 50;

?

For example. Won’t that always keep it away from the cursor? What kind of algorithm are you running?

onClipEvent (load) {
 scopeposition = function() {
  this._x = _root._xmouse
  this._y = _root._ymouse
  updateAfterEvent();
 }
 recoil = function() {
  this._x = _root._xmouse + (Math.random()*10)
  this._y = _root._ymouse + (Math.random()*10)
 }
 fire = function() {
  recoil();
 }
}
onClipEvent (enterFrame) {
 scopeposition();
}
on (press) {
 recoil();
}

I am a beginner scripter, if you can’t tell.

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();}

}
recoil = function() {
this._x = _root._xmouse + (Math.random()*10)
this._y = _root._ymouse + (Math.random()*10)
isRecoil = true
}

Man, I thought you had it!! It does the recoil effect, but then it doesn’t follow the mouse anymore, it just stays there where it “recoiled”.

It might be because I messed up the AS though, I’m new to booleans here is what I put:
in the main timeline

Mouse.hide();
stop();
isRecoil = new Boolean()

in the scope itself

onClipEvent (load) {
 shot = true;
 scopeposition = function () {
  if (!isRecoil) {
   this._x = _root._xmouse;
   this._y = _root._ymouse;
   updateAfterEvent();
  }
 };
 recoil = function () {
  this._x = _root._xmouse+(Math.random()*10);
  this._y = _root._ymouse+(Math.random()*10);
  isRecoil = true
  updateAfterEvent();
 };
 fire = function () {
  if (shot == true) {
   this.gotoAndPlay(2);
   recoil();
  }
 };
}
onClipEvent (enterFrame) {
 scopeposition();
}
on (press) {
 recoil();
}

Oh, and thank you VERY [U]VERY[/U] much for taking the time to help me :egg:

naw you got it right

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)

Yea, this would probably be better, but too bad im an actionscript newbie and don’t know how to do it :stuck_out_tongue:

Basically, all I ahve to do is find a way to put a isRecoil = false somewhere? I think I know how to do that.

By the way, what does the ! in front of !isRecoil mean? I tried googling it and everything and I couldn’t find it.

Oh, and is there like a point system or kudo system that I can reward you with or something? You damn well deserve it.

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