Kamera dreht falsche Richtung Objekt nicht
Übersicht

![]() |
BastianABetreff: Kamera dreht falsche Richtung Objekt nicht |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo,
ich programmiere gerade ein Spiel wo man mit einer Trambahn fahren muss. Die Kamera "sitzt" auf dem Zug darauf, und fährt auch mit, sobald die Trambahn in eine Kurve fährt und das Objekt anhand der Meter-Zahl gedreht werden soll, dreht sich die Kamera in eine komplett falsche Richtung. Habe schon mehrere Möglichkeiten ausprobiert - aber ohne Erfolg. Hier mein Code: Code: [AUSKLAPPEN] Graphics3D 1280, 1024, 32, 0 SetBuffer BackBuffer() light = CreateLight() RotateEntity light, 90, 0, 0 Global cam1=CreateCamera(Tram) font = LoadFont("Calibri",20,1) SetFont font Tram = LoadMesh("1/nikon.3ds") PositionEntity Tram, 0, 0, 0 Map = LoadMesh("map.3ds") PositionEntity map, 0, 0, 0 Box = LoadMesh("Skybox.3ds") PositionEntity map, 0, 0, 0 CameraRange cam1, 0.001, 40001 PositionEntity cam1, 0, 1.8, 7 Global S# = 0 Global G# = 0 Baum1 = CreateCube() PositionEntity Baum1, -5, 0, 30 textur1 = CreateTexture (1024, 1024, 4) EntityTexture baum1, textur1 While Not KeyHit(1) If KeyDown(200) Then G = G + 0.1 S = S + 1 MoveEntity Tram, 0, 0, +0.1 MoveEntity cam1, 0, 0, +0.1 EndIf If KeyDown(208) Then G = G - 0.1 S = S - 1 MoveEntity Tram, 0, 0, -0.1 MoveEntity cam1, 0, 0, -0.1 EndIf If KeyDown(14) Then PositionEntity cam1, 0, 1.8, 7 EndIf If KeyDown(17) Then MoveEntity cam1, 0, 0, +0.02 EndIf If KeyDown(44) MoveEntity cam1, 0, 0, +0.2 EndIf If KeyDown(31) Then MoveEntity cam1, 0, 0, -0.02 EndIf If KeyDown(32) Then MoveEntity cam1, +0.02, 0, 0 EndIf If KeyDown(201) Then MoveEntity cam1, 0, +0.01, 0 EndIf If KeyDown(209) Then MoveEntity cam1, 0, -0.01, 0 EndIf If KeyDown(30) Then MoveEntity cam1, -0.02, 0, 0 EndIf If KeyDown(16) Then TurnEntity cam1,0,+10,0 EndIf If KeyDown(18) Then TurnEntity cam1,0,-10,0 EndIf If S = 441 Then RotateEntity Tram, 0, 5, 0, 1 RotateEntity cam1, 0, 5, 0, 1 EndIf If S = 515 Then RotateEntity Tram, 0, 5, 0, 1 EndIf If S = 562 Then RotateEntity Tram, 0, 5, 0, 1 EndIf If G > 62 Then G = 62 EndIf SoundId=LoadSound("Sounds\Motor2.wav") LoopSound SoundId If KeyDown(11) Then Ma = Ma + 1 If Ma = 1 Then ChannelId=PlaySound(SoundId) If Ma = 2 Then StopChannel ChannelId If Ma = 3 Then Ma = 0 EndIf If KeyDown(28) Then G = 0 EndIf UpdateWorld RenderWorld Text 0,10,"Aktuelle Geschwindigkeit: " + G Text 0,25,"Gefahrene Meter: " + S Flip Wend End |
||
![]() |
ZaP |
![]() Antworten mit Zitat ![]() |
---|---|---|
Du hast die Reihenfolge vertauscht. Zuerst wird die Kamera erstellen, mit Tram als Parent, aber Tram ist zu dem Zeitpunkt noch 0, denn die Variable wird erst weiter unten mit dem Mesh initialisiert.
Im Klartext: Erst das Mesh laden, und die Rückgabe in Tram speichern, dann die Kamera erstellen, mit Tram als Parent. Wenn Du die Reihenfolge so beibehalten möchtest, kannst Du auch unter Tram einfach mit EntityParent ![]() Die Kamera fährt nur mit, weil sie jedes Frame ein Stück (+0.1 auf der Z-Achse) nach vorne gesetzt wird, so wie der Zug. Wenn die Kamera nun ein Parent hat, solltest Du diese Zeile rausnehmen. |
||
Starfare: Worklog, Website (download) |
![]() |
BastianA |
![]() Antworten mit Zitat ![]() |
---|---|---|
Danke, klappt jetzt.
Ich habe noch eine Frage die nicht ganz zum Thema passt. Bei einer Kurve soll die Tram ja auf den Schienen bleiben, doch wie mache ich das bloß am Besten. Ich habe es erstmal mit Kollisionen probiert, da aber die Schiene nicht gerade hoch ist, ist die Kollision gleich 0. Ich dachte man könnte pro Tastendruck eine Variable erhöhen. WIe man oben sieht wird pro Pfeil Nach Oben Druck die Variable S um 0.1 erhöht. Nun könnte man prüfen wenn Variable S z.B: 400 ist, soll sie sich um 5 Grad drehen. Das klappt auch, aber der nächste Code bei 450 klappt nicht mehr. Sie dreht sich einmal und dann nichtmehr. Hier der Code: Code: [AUSKLAPPEN] Graphics3D 1280, 1024, 32, 0 SetBuffer BackBuffer() light = CreateLight() RotateEntity light, 90, 0, 0 font = LoadFont("Calibri",20,1) SetFont font Tram = LoadMesh("1/nikon.3ds") PositionEntity Tram, 0, 0, 0 Map = LoadMesh("map.3ds") PositionEntity map, 0, 0, 0 Box = LoadMesh("Skybox.3ds") PositionEntity map, 0, 0, 0 Global cam1=CreateCamera(Tram) CameraRange cam1, 0.001, 40001 PositionEntity cam1, 0, 1.8, 7 Global S# = 0 Global G# = 0 Baum1 = CreateCube() PositionEntity Baum1, -5, 0, 30 textur1 = CreateTexture (1024, 1024, 4) EntityTexture baum1, textur1 While Not KeyHit(1) If KeyDown(200) Then G = G + 0.1 S = S + 1 MoveEntity Tram, 0, 0, +0.1 EndIf If KeyDown(208) Then G = G - 0.1 S = S - 1 MoveEntity Tram, 0, 0, -0.1 EndIf If KeyDown(14) Then PositionEntity cam1, 0, 1.8, 7 EndIf If KeyDown(17) Then MoveEntity cam1, 0, 0, +0.02 EndIf If KeyDown(44) MoveEntity cam1, 0, 0, +0.2 EndIf If KeyDown(31) Then MoveEntity cam1, 0, 0, -0.02 EndIf If KeyDown(32) Then MoveEntity cam1, +0.02, 0, 0 EndIf If KeyDown(201) Then MoveEntity cam1, 0, +0.01, 0 EndIf If KeyDown(209) Then MoveEntity cam1, 0, -0.01, 0 EndIf If KeyDown(30) Then MoveEntity cam1, -0.02, 0, 0 EndIf If KeyDown(16) Then TurnEntity cam1,0,+10,0 EndIf If KeyDown(18) Then TurnEntity cam1,0,-10,0 EndIf If S = 450 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 451 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 452 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 453 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 454 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 455 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 456 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 457 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 458 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 459 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 460 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 460 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 461 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 462 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 463 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 464 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 465 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 466 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 467 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 468 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 469 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 470 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 470 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 471 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 472 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 473 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 474 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 475 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 476 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 477 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 478 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 479 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 480 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 480 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 481 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 482 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 483 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 484 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 485 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 486 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 487 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 488 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 489 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 490 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 490 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 491 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 492 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 493 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 494 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 495 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 496 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 497 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 498 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 499 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 500 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 501 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 502 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 503 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 504 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 505 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 506 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 507 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 508 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 509 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 510 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 510 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 511 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 512 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 513 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 514 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 515 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 516 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 517 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 518 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 519 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 520 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 520 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 521 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 522 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 523 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 524 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 525 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 526 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 527 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 528 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 529 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 530 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 530 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 531 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 532 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 533 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 534 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 535 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 536 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 537 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 538 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 539 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 540 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 540 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 541 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 542 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 543 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 544 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 545 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 546 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 547 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 548 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 549 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If S = 550 Then RotateEntity Tram, 0, +01, 0, 1 EndIf If G > 62 Then G = 62 EndIf SoundId=LoadSound("Sounds\Motor2.wav") LoopSound SoundId If KeyDown(11) Then Ma = Ma + 1 If Ma = 1 Then ChannelId=PlaySound(SoundId) If Ma = 2 Then StopChannel ChannelId If Ma = 3 Then Ma = 0 EndIf If KeyDown(28) Then G = 0 EndIf UpdateWorld RenderWorld Text 0,10,"Aktuelle Geschwindigkeit: " + G Text 0,25,"Gefahrene Meter: " + S Flip Wend End |
||
![]() |
ZaP |
![]() Antworten mit Zitat ![]() |
---|---|---|
Dafür musst Du TurnEntity![]() ![]() Bevor Du 1000 If-Bedingungen schreibst, würde ich dir empfehlen, so etwas wie ein Bot Routing zu machen. Das heißt, der Zug hat bestimmte Wegpunkte, die Informationen über ihren Standort (x, y, z) und den Zielwinkel enthalten, den der Zug annimmt, wenn er passiert. Das ganze lässt sich über Type ![]() |
||
Starfare: Worklog, Website (download) |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group