Hi Leute!
Wie die meisten wissen hab ich mein Projekt Flutch am Laufen.
Ich bin dabei am einstellen der Standardeinstellungen fürs Herumlaufen des Charakters usw....
Doch ich scheitere im Moment an einem Problem:
--> Mein Charakter sieht immer in die gleiche Richtung..
Ich müsste ihn genau in diese Richtung Rotieren in die er läuft.
Ich hab mal eine Berechnung probiert, die anber nicht funkt...
Könnt ihr mir weiterhelfen:
Spoiler anzeigen
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include "../au3Irrlicht2.au3"
#include <Misc.au3>
#include <File.au3>
opt("MustDeclareVars", True)
HotKeySet("{ESC}", "_exit")
Global $degree = -180
Global $degZ = 70
Global $BSPMesh, $BSPNode, $Camera, $MD2Mesh, $SceneNode, $MeshTexture, $MeshTexture2, $selector, $outHitPosition, $outFalling
Global $screen_width, $screen_height, $gravity[3], $velocity[3], $ellipsoidRadius[3]
Global $aMousePos[2], $aPoint[3], $aDirect[3], $aCamPos[3], $aDirectCha[3], $DifV[3], $DivL, $aAlpha, $Light[5]
Global $dir = _PathFull( @ScriptDir & "\..\Meshes\md2\" ) ;
[/autoit] [autoit][/autoit] [autoit]$screen_width = 800
$screen_height = 600
_IrrStart( $IRR_EDT_OPENGL, $screen_width, $screen_height, $IRR_BITS_PER_PIXEL_32, _
$IRR_WINDOWED, $IRR_NO_SHADOWS, $IRR_IGNORE_EVENTS, _
$IRR_VERTICAL_SYNC_OFF )
_IrrSetWindowCaption( "Flutch - Das neue Rollenspiel" )
[/autoit] [autoit][/autoit] [autoit]$MeshTexture = _IrrGetTexture( $dir & "test.bmp" )
$BSPMesh = _IrrGetMesh( $dir & "_test7.obj" )
$BSPNode = _IrrAddMeshToSceneAsOcttree( $BSPMesh )
_IrrSetNodeMaterialFlag( $BSPNode, $IRR_EMF_LIGHTING, $IRR_OFF )
_IrrSetNodeScale( $BSPNode, 10, 10, 10 )
_IrrSetNodeMaterialTexture( $BSPNode, $MeshTexture, 1 )
_IrrSetNodeMaterialFlag( $BSPNode, $IRR_EMF_LIGHTING, $IRR_OFF )
$MD2Mesh = _IrrGetMesh( $dir & "test6.obj" )
$MeshTexture2 = _IrrGetTexture( $dir & "test5.pcx" )
$SceneNode = _IrrAddMeshToScene( $MD2Mesh )
_IrrSetNodeScale( $SceneNode, 2, 2, 2 )
_IrrSetNodeMaterialTexture( $SceneNode, $MeshTexture2, 0 )
_IrrSetNodeMaterialFlag( $SceneNode, $IRR_EMF_LIGHTING, $IRR_OFF )
$selector = _IrrGetCollisionGroupFromComplexMesh( $BSPMesh, $BSPNode )
$aPoint[0] = 1900.0
$aPoint[1] = 100.0
$aPoint[2] = 1300.0
$gravity[0] = 0.0
$gravity[1] = -2.8
$gravity[2] = 0.0
$velocity[0] = 0.0
$velocity[1] = 2.0
$velocity[2] = 0.0
$aCamPos[0] = 1750.0
$aCamPos[1] = 149.0
$aCamPos[2] = 1369.0
$aDirectCha[0] = 0.0
$aDirectCha[1] = 0.0
$aDirectCha[2] = 0.0
$ellipsoidRadius[0] = 25.0
$ellipsoidRadius[1] = 50.0
$ellipsoidRadius[2] = 25.0
$Camera = _IrrAddCamera( $aCamPos[0], $aCamPos[1], $aCamPos[2], $aPoint[0], $aPoint[1], $aPoint[2] )
_IrrSetNodePosition($SceneNode, $aPoint[0], $aPoint[1], $aPoint[2])
_IrrHideMouse()
MouseMove( @DesktopWidth/2, @DesktopHeight/2, 0 )
$aMousePos[0] = 0.0
$aMousePos[1] = 0.0
WHILE _IrrRunning()
_IrrBeginScene( 55,55,55 )
_Direction_calc()
[/autoit] [autoit][/autoit] [autoit]_IrrGetCollisionResultPosition ( _
$selector, _
$aPoint, _
$ellipsoidRadius, _
$velocity, _
$gravity, _
0.0005, _
$aPoint, _
$outHitPosition, _
$outFalling )
_move()
_IrrSetCameraTarget( $Camera, $aPoint[0], $aPoint[1], $aPoint[2] )
_IrrDrawScene()
[/autoit] [autoit][/autoit] [autoit]_IrrEndScene()
WEND
Func _exit()
_IrrStop()
Exit
EndFunc ; _exit
Func _Direction_calc()
$aMousePos = MouseGetPos()
MouseMove( @DesktopWidth/2, @DesktopHeight/2, 0 )
$aMousePos[0] -= @DesktopWidth/2
$aMousePos[1] -= @DesktopHeight/2
If $aMousePos[0] < 0 Then
$degree -= $aMousePos[0]/15
If $degree >= 180 Then $degree = -180
ElseIf $aMousePos[0] > 0 Then
$degree -= $aMousePos[0]/15
If $degree <= -180 Then $degree = 180
EndIf
If $aMousePos[1] < 0 Then
If $degZ < 179 Then $degZ -= $aMousePos[1]/15
ElseIf $aMousePos[1] > 0 Then
If $degZ > 1 Then $degZ -= $aMousePos[1]/15
EndIf
$aDirect[0] = $aPoint[0] - $aCamPos[0]
$aDirect[1] = $aPoint[1] - $aCamPos[1]
$aDirect[2] = $aPoint[2] - $aCamPos[2]
$velocity[0] = 0.0
$velocity[2] = 0.0
If _IsPressed("57") Then
$velocity[0] = $aDirect[0]/100
$velocity[2] = $aDirect[2]/100
$DifV[0] = -$aDirectCha[0] + $aDirect[0]
$DifV[2] = -$aDirectCha[2] + $aDirect[2]
$DivL = (($DifV[0]^2 + $DifV[2]^2)^(1/2))/2
$aAlpha = ASin( $DivL / ( ($aDirectCha[0]^2 + $aDirectCha[2]^2) ^ (1/2) ))
$aDirectCha[0] = $aDirect[0]
$aDirectCha[2] = $aDirect[2]
ElseIf _IsPressed("53") Then
$velocity[0] = -$aDirect[0]/100
$velocity[2] = -$aDirect[2]/100
EndIf
If _IsPressed("41") Then
$velocity[0] = -$aDirect[2]/100
$velocity[2] = $aDirect[0]/100
ElseIf _IsPressed("44") Then
$velocity[0] = $aDirect[2]/100
$velocity[2] = -$aDirect[0]/100
EndIf
EndFunc
Func _move()
Local Const $pi = 3.14159265358979323846264338327950288419716939937510582097
Local Const $deg2rad = $pi/180
Local $rad = $degree * $deg2rad
$aCamPos[0] = 200 * Sin($degZ * $deg2rad) * Cos($rad) + $aPoint[0]
$aCamPos[2] = 200 * Sin($degZ * $deg2rad) * Sin($rad) + $aPoint[2]
$aCamPos[1] = 200 * Cos($degZ * $deg2rad) + $aPoint[1]
$aAlpha = $aAlpha / $deg2rad
_IrrSetNodePosition($Camera, $aCamPos[0], $aCamPos[1], $aCamPos[2])
_IrrSetNodePosition($SceneNode, $aPoint[0], $aPoint[1], $aPoint[2])
_IrrSetNodeRotation($SceneNode, 0, $aAlpha, 0)
EndFunc