Foros del Web » Creando para Internet » Flash y Actionscript »

Calcular angulo de otro objeto

Estas en el tema de Calcular angulo de otro objeto en el foro de Flash y Actionscript en Foros del Web. Bueno esto creo que es muy largo asi que espero que tengan paciencia y me puedan ayudar.. Les comento .... Esto trata de un juego ...
  #1 (permalink)  
Antiguo 14/01/2006, 00:06
 
Fecha de Ingreso: enero-2006
Mensajes: 4
Antigüedad: 18 años, 3 meses
Puntos: 0
Calcular angulo de otro objeto

Bueno esto creo que es muy largo asi que espero que tengan paciencia y me puedan ayudar..

Les comento .... Esto trata de un juego de futbol, en el cual hay 2 jugadores Principales los cuales se manejan con las flechas uno y con W,S,D,A el otro... El tema es asi hay una pelota .. y 3 jugadores de cada equipo , cada jugador(PC) patea a un jugar random.. en direccion contraria osea haci el arco del otro.. Lo unico que hacen es acercarce a la pelota y patearla en un angulo RANDOM.
Los personajes principales se mueve y pueden patear..

Ahora bien el juego esta visto de arriba muy arriba y los jugadores se mueven girando y avanzando .... Ahora bien , lo que yo quiero es hacer que los jugadores(pc) no pateen la pelota haci el lado contrario sino que me la pasen a mi al Principal..

Nose si se entiende.. Pero aqui dejo los codigos de todo..
Las variables que utilize son un poco raras , tengo muy mala organizacion.



EL JUGADOR PRINCIPAL TIENE EL SIGUIENTE CODIGO.
Código:

onClipEvent (enterFrame) {
if (_root.pelota.hitTest(this)) {
_root.quien = 1;
_root.pelota._x = this._x;
_root.pelota._y = this._y;
if (Key.isDown(71)) {
_root.pelota.speed += 10;
_root.pelota._rotation = this._rotation;
}
} else {
_root.quien = "nola";
}
if (Key.isDown(87)) {
play();
speed += 1.5;
} else {
speed--;
}
if (speed<=0) {
speed = 0;
}
if (speed>=1.8) {
speed = 1.8;
}
if (Key.isDown(65)) {
_rotation -= 5;
}
if (Key.isDown(68)) {
_rotation += 5;
}
_x += Math.sin(_rotation*(Math.PI/180))*speed;
_y += Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (this._y<=44) {
this._y = 44;
}
if (this._y>=334) {
this._y = 334;
}
if (this._x<=19) {
this._x = 19;
}
if (this._x>=518) {
this._x = 518;
}
}



Ese seria el Jugador principal , el que uno maneja..


Ahora , la maquina de tu mismo equipo..
El que patea en un angulo RANDOM
Código:

onClipEvent (enterFrame) {
jua = random(180);
updateAfterEvent();
if (_root.quien == 0 and _root.pelota.hitTest(_root.miarea2) or _root.quien == "nola" and _root.pelota.hitTest(_root.miarea2)) {
xdif = _root.pelota._x-this._x;
ydif = _root.pelota._y-this._y;
angulo = Math.atan2(ydif, xdif);
this._x += 1.5*Math.cos(angulo);
this._y += 1.5*Math.sin(angulo);
this.play();
}
if (_root.pelota.hitTest(this)) {
_root.pelota.speed += random(5);
_root.pelota._rotation = jua;
}
angulo = angulo*180/Math.PI;
this._rotation = angulo;
}




Y por ultimo la PELOTA (BALON)

Código:

onClipEvent (enterFrame) {
_rotation -= speed;
_rotation += speed;
speed *= .87;
_x += Math.sin(_rotation*(Math.PI/180))*speed;
_y += Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (this._y<=76.7) {
this._y = 76.7;
}
if (this._y>=329) {
this._y = 329;
}
if (this._x<=7) {
this._x = 7;
}
if (this._x>=532.5) {
this._x = 532.5;
}
}



Espero que lo entiendan y me puedan ayudar muchisimas gracias desde ya un saludo enorme y gracias de antemano.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:32.