Comunidad de diseño web y desarrollo en internet online

agregar aceleración a objeto que sigue puntero mouse

Citar            
MensajeEscrito el 26 Ene 2010 09:25 pm
Buenas, encontré un .fla llamado Personaje3DSigueElMouse y me sería de gran utilidad poderle agregar al personaje que allí se presenta, alguna propiedad que le posibilite acelerar en la medida que se acerca al puntero del mouse.

Es esto posible, y de ser así, podrían ejemplificármelo en función del código del archivo?

Agradezco de antemano.

Por incubo

53 de clabLevel



 

firefox
Citar            
MensajeEscrito el 27 Ene 2010 12:55 am
Postea el código no el .fla, nadie lo bajará y no esta bien visto.

Saludos, Hernán . -

Por Hernán

BOFH

6148 de clabLevel

19 tutoriales
23 articulos

Genero:Masculino   REC Desarrollador de GAIA

Marketing & IT

firefox
Citar            
MensajeEscrito el 27 Ene 2010 07:35 am
var Speed:Number = 1 // Velocidad del personaje
var TmpXY:Number = 0;

onEnterFrame = function() {
gotoSpotX = this._parent._xmouse;
gotoSpotY = this._parent._ymouse;

// calculate angle of current position to target position
delta_x = this._x-gotoSpotX;
delta_y = this._y-gotoSpotY;
targetRotation = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
if (targetRotation<0){
targetRotation += 360//Acomoda el angulo para que sea de 360 grados
}

// move beetle toward the target and stop when it gets there
if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>Speed) {
_y -= Speed*Math.cos(targetRotation*(Math.PI/180));
_x += Speed*Math.sin(targetRotation*(Math.PI/180));
this.Fachadas.Parado = false; //Controla fachada de estar parado
}else{
this.Fachadas.Parado = true;
}

//
// loop to opposite side of the masked area when the beetle travels off-screen
if (_y<0) {
_y = 400;
}
if (_y>400) {
_y = 0;
}
if (_x<0) {
_x = 400;
}
if (_x>400) {
_x = 0;
}

// Asigna el cambio de fachadas
if (targetRotation<45){
this.Fachadas.Angulo = 0;
}else if (targetRotation<90){
this.Fachadas.Angulo = 45;
}else if (targetRotation<135){
this.Fachadas.Angulo = 90;
}else if (targetRotation<180){
this.Fachadas.Angulo = 135;
}else if (targetRotation<225){
this.Fachadas.Angulo = 180;
}else if (targetRotation<270){
this.Fachadas.Angulo = 225;
}else if (targetRotation<315){
this.Fachadas.Angulo = 270;
}else if (targetRotation<360){
this.Fachadas.Angulo = 0;
}



this.Direccion._rotation = targetRotation; // Borrar esto
XY = int(_x) + " ; " + int(_y); // Borrar esto
Ang = this.Fachadas.Angulo; // Borrar esto

Por incubo

53 de clabLevel



 

firefox
Citar            
MensajeEscrito el 03 Feb 2010 07:07 am
Aquí la preciada respuesta:

var Speed:Number = 1 // Velocidad del personaje
var TmpXY:Number = 0;
var vel_ini:Number = 1;
var vel_fin:Number = 5;
var vel_fps:Number = 60;
var vel_tmp:Number = 1.5;
var vel_aumento:Number = ( vel_fin - vel_ini ) / ( vel_fps * vel_tmp)
onEnterFrame = function() {
gotoSpotX = this._parent._xmouse;
gotoSpotY = this._parent._ymouse;
// calculate angle of current position to target position
delta_x = this._x-gotoSpotX;
delta_y = this._y-gotoSpotY;
targetRotation = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
if (targetRotation<0){
targetRotation += 360//Acomoda el angulo para que sea de 360 grados
}
// move beetle toward the target and stop when it gets there
if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>Speed) {
Speed += vel_aumento
if( Speed >= vel_fin ){
Speed = vel_fin
}
_y -= Speed*Math.cos(targetRotation*(Math.PI/180));
_x += Speed*Math.sin(targetRotation*(Math.PI/180));
this.Fachadas.Parado = false; //Controla fachada de estar parado
}else{
Speed = vel_ini
this.Fachadas.Parado = true;
}

//
// loop to opposite side of the masked area when the beetle travels off-screen
if (_y<0) {
_y = 400;
}
if (_y>400) {
_y = 0;
}
if (_x<0) {
_x = 400;
}
if (_x>400) {
_x = 0;
}

// Asigna el cambio de fachadas
if (targetRotation<45){
this.Fachadas.Angulo = 0;
}else if (targetRotation<90){
this.Fachadas.Angulo = 45;
}else if (targetRotation<135){
this.Fachadas.Angulo = 90;
}else if (targetRotation<180){
this.Fachadas.Angulo = 135;
}else if (targetRotation<225){
this.Fachadas.Angulo = 180;
}else if (targetRotation<270){
this.Fachadas.Angulo = 225;
}else if (targetRotation<315){
this.Fachadas.Angulo = 270;
}else if (targetRotation<360){
this.Fachadas.Angulo = 0;
}
this.Direccion._rotation = targetRotation; // Borrar esto
XY = int(_x) + " ; " + int(_y); // Borrar esto
Ang = this.Fachadas.Angulo; // Borrar esto
}

Por incubo

53 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.