Zurück   Flashforum > Flash > ActionScript > Spielkonzepte und Spieleprogrammierung

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 28-11-2006, 17:13   #1 (permalink)
Neuer User
 
Registriert seit: Nov 2006
Beiträge: 6
[sin,cos,tan] Objekt verfolgt Punkt (Rotation)

Morgen !

Für viele Spiele ist das einfach unmissbar - ein Turret welcher automatisch auf ein Objekt zielt.

Doch ich scheitere beim Grundlegenden... da ich bezgl. Sinus, Cosinus und Tanges ne Nulpe bin (auch was Bogenmass und Winkel angeht) und dann noch die Portation zu Flash hinzukommt, bitte ich euch, mir nen Code zu pasten der das anständig macht bzw. einen Hilfeansatz geben

Mein bisheriger Code, funzt nur.. irgendwie... halb... Gnaaaz..
Code:
turret.onEnterFrame = function() {
	deltax = _xmouse - this._x;
	deltay = _ymouse - this._y;
	_root.txtx.text = deltax;
	_root.txty.text = deltay;
	
	this.k = deltay/deltax;
	this._rotation = Math.asin(this.k)*180/Math.PI;
	
}
function to_bogen(input_winkel:Number) {
	return input_winkel * Math.PI / 180;
}


Mr.Jeep
Mr.Jeep ist offline   Mit Zitat antworten
Alt 28-11-2006, 17:27   #2 (permalink)
new user
 
Benutzerbild von PinkDragon
 
Registriert seit: Oct 2005
Beiträge: 140
nimm statt asin(w), atan2(y,x);

sin(w) = gegen/hyp
cos(w) = an/hyp
tan(w) = gegen/an

mfg
PD
PinkDragon ist offline   Mit Zitat antworten
Alt 28-11-2006, 17:42   #3 (permalink)
Neuer User
 
Registriert seit: Nov 2006
Beiträge: 6
Zitat:
Zitat von PinkDragon Beitrag anzeigen
nimm statt asin(w), atan2(y,x);

sin(w) = gegen/hyp
cos(w) = an/hyp
tan(w) = gegen/an

mfg
PD
Das ging schnell, und das Ergebnis sieht auch schon viel besser aus, aber ganz richtig is noch nicht (Anhang).

Code:
turret.onEnterFrame = function() {
	deltax = _xmouse - this._x;
	deltay = _ymouse - this._y;
	this._rotation = Math.atan2(deltax, deltay) * 180 / Math.PI;
};
function to_bogen(input_winkel:Number) {
	return input_winkel * Math.PI / 180;
}
Angehängte Dateien
Dateityp: rar turret_swf.rar (449 Bytes, 21x aufgerufen)
Mr.Jeep ist offline   Mit Zitat antworten
Alt 28-11-2006, 17:52   #4 (permalink)
new user
 
Benutzerbild von PinkDragon
 
Registriert seit: Oct 2005
Beiträge: 140
PHP-Code:
Math.atan2(Y,X); //zuerst Y 
mfg
PD
PinkDragon ist offline   Mit Zitat antworten
Alt 28-11-2006, 18:12   #5 (permalink)
Neuer User
 
Registriert seit: Nov 2006
Beiträge: 6
Zitat:
Zitat von PinkDragon Beitrag anzeigen
PHP-Code:
Math.atan2(Y,X); //zuerst Y 
mfg
PD
Vielen Dank !
Mr.Jeep ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 18:25 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele