Realistischere Steuerung?
Übersicht

![]() |
[Wumme]Betreff: Realistischere Steuerung? |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo.
Habe ein Objekt, welches auf Tastendruck (Pfeiltasten) in die jeweilige Richtung "schwebt". Sobald losgelassen wird, steht auch ruckartig mein Objekt wieder still. Kann man mir evtl. ein paar Tipps und Hilfen geben, wie ich mein Objekt dazu bringe, langsam zum Stillstand zu kommen, sobald man die Pfeiltasten loslässt? Gruß Wumme |
||
- Zuletzt bearbeitet von [Wumme] am Mi, Jan 19, 2005 1:12, insgesamt einmal bearbeitet
Klaas |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
hier, schau mal.
Die gleiche Methode kannst du auch für 3D verwenden. Denk dir einfach einen neuen Vektor (Z) dazu. Code: [AUSKLAPPEN] Graphics 800,600,32,2 SetBuffer(BackBuffer()) x# = 300 y# = 400 timer = CreateTimer(25) While Not KeyHit(1) WaitTimer(timer) ;den Bewegungsvektor je nach richtung verändern If KeyDown(200) Then vy# = vy - 1 End If If KeyDown(208) Then vy# = vy + 1 End If If KeyDown(203) Then vx# = vx - 1 End If If KeyDown(205) Then vx# = vx + 1 End If ;hier die Reibung anwenden vx = vx * 0.9 vy = vy * 0.9 ;den bewegungsvektor auf die Position anwenden x = x + vx y = y + vy ;zeichnen Oval(x-4,y-4,9,9) Flip() Cls Wend |
||
![]() |
[Wumme] |
![]() Antworten mit Zitat ![]() |
---|---|---|
Als 2D-Beispiel funktioniert es genauso, wie ich es mir vorstellte.
Habe dies mal probiert nun für mein 3D-Programm hinzubekommen. Allerdings bleibt meine Kugel nicht stehen, sondern hält die Geschwindigkeit ![]() ![]() Code: [AUSKLAPPEN] Graphics3D 800, 600 SetBuffer BackBuffer() AmbientLight 200,200,200 sun = CreateLight () RotateEntity sun, 0, 45, 0 Global camera = CreateCamera() PositionEntity camera, 0,2,-20 sphere = CreateSphere() x# = 0 y# = 0 timer = CreateTimer(20) While Not KeyHit(1) WaitTimer(timer) If KeyDown(208) Then vy# = vy - 0.01 End If If KeyDown(200) Then vy# = vy + 0.01 End If If KeyDown(203) Then vx# = vx - 0.01 End If If KeyDown(205) Then vx# = vx + 0.01 End If vx = vx * 0.9 vy = vy * 0.9 x = x + vx y = y + vy MoveEntity sphere, x,y,0 UpdateWorld RenderWorld Flip Wend |
||
![]() |
Klip |
![]() Antworten mit Zitat ![]() |
---|---|---|
Das mit dem Tempo ist auch nicht all zu schwer.
Code: [AUSKLAPPEN] Graphics3D 800, 600 SetBuffer BackBuffer() AmbientLight 200,200,200 sun = CreateLight () RotateEntity sun, 0, 45, 0 Global camera = CreateCamera() PositionEntity camera, 0,2,-20 sphere = CreateSphere() x# = 0 y# = 0 vx# = 0 vy# = 0 timer = CreateTimer(20) While Not KeyHit(1) WaitTimer(timer) If KeyDown(208) Then vy = (vy - 0.01) * 0.9 End If If KeyDown(200) Then vy = (vy + 0.01) * 0.9 End If If KeyDown(203) Then vx = (vx - 0.01) * 0.9 End If If KeyDown(205) Then vx = (vx + 0.01) * 0.9 End If x = x + vx y = y + vy ; --------------------------###################### If vx > 0 vx = vx - 0.01 EndIf If vx < 0 vx = vx + 0.01 EndIf If vy > 0 vy = vy - 0.01 EndIf If vy < 0 vy = vy + 0.01 EndIf ;----------------------------------#################### MoveEntity sphere, x,y,0 UpdateWorld RenderWorld Flip Wend End Ich habe das jetzt mal so aus dem Kopf gemacht. Bei meinem Astrolander-Projekt habe ich das Problem ebenfalls so gelöst. Falls es jetzt nicht geklappt hat oder es noch sehr viel einfacher geht, dann würde ich gerne was dazulernen. |
||
Klaas |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Dein wesentliches Problem liegt hier
Code: [AUSKLAPPEN] x = x + vx y = y + vy MoveEntity sphere, x,y,0 in 2D arbeitet man immer mit absoluten Koordinaten. In 3D dagegen kann man auch Transformieren. Das würde gehen : Code: [AUSKLAPPEN] x = x + vx y = y + vy PositionEntity sphere, x,y,0 oder auch das: Code: [AUSKLAPPEN] MoveEntity sphere, vx,vy,0 |
||
![]() |
[Wumme] |
![]() Antworten mit Zitat ![]() |
---|---|---|
Geil. Herzlichsten Dank ![]() |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group