About Monkey 2 › Forums › Monkey 2 Programming Help › My controls change when I rotate my player in my 3D game
This topic contains 0 replies, has 1 voice, and was last updated by En929 7 hours, 16 minutes ago.
-
AuthorPosts
-
January 19, 2019 at 10:53 am #15958
In my 3D game, I am having problems with my rotation. When I first start the game, the player goes Forward (Z), Backwards (Z); it rotates to the Right(Y) and rotates the Left (Y) normally. However, when I rotate my player 90 degrees. After that, when I press the up button, the up button starts acting like the Right button, etc. and all of the controls change and they change in every 90 degrees in which my player is rotated. Thus, what do I add to my code to get the controls to go in the way that the player is facing. My code is below. Thanks:
Monkey
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151'Skybox 1015 X 1030 and 2045 X 995 for a 4095 X 3070 sized'pictureNamespace myapp#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"#Import "<mojo3d-loaders>"#Import "Man.b3d"#Import "Man.jpg"#Import "Tower.png"#Import "Maplewood.b3d"Using std..Using mojo..Using mojo3d..Class MyWindow Extends Window'Initialize everything that you're going to useField _scene:SceneGlobal _camera:CameraField _light:LightField _ground:ModelField Man:ModelField Jack_in_the_Box: ModelField _animator:AnimatorField MoveForwardZ: Float = 0.2Field MoveBackwardsZ: Float = -0.2Field ManX:Float = 0 '// x position on the mapField ManY:Float = -40Field ManZ: Float = -100Method New( title:String="The World Doesn't Apply to Him",width:Int=800,height:Int=600,flags:WindowFlags=WindowFlags.Resizable )Super.New( title,width,height,flags )_scene=New SceneMan=Model.LoadBoned( "asset::Man.b3d" )Man.Scale=New Vec3f( .1)Man.Position = New Vec3f(0, 30,10)_camera=New Camera( Man)'_camera.Near= 2_camera.Far=100000_camera.Position = New Vec3f(0, 48,-10) 'create light'_light=New Light_light.Rotate( 75,150,0 ) 'aim directional light 'down' - Pi/2=90 degrees._light.CastsShadow=True_ground=Model.CreateBox( New Boxf( 0,0,0,0,0,0 ),1,1,1,New PbrMaterial( Color.Green ) )_ground.CastsShadow=FalseJack_in_the_Box =Model.Load( "asset::Maplewood.b3d")_animator=Man.AnimatorJack_in_the_Box.Move( 0,40,300)Jack_in_the_Box.Scale = New Vec3f(0.5, 0.5, 0.5)_animator.MasterSpeed=0.5Local anim2:=_animator.Animations[0].Slice( "Idle",1,1,AnimationMode.Looping )Local anim1:=_animator.Animations[0].Slice( "Walk",2,30,AnimationMode.Looping )Local anim3:=_animator.Animations[0].Slice( "Punch",31,99,AnimationMode.OneShot )_animator.Animations.Add( anim1 )_animator.Animations.Add( anim2 )_animator.Animations.Add( anim3 )EndMethod OnRender( canvas:Canvas ) OverrideRequestRender()If _animator.Animating?.Name<>"Punch"If Keyboard.KeyHit( Key.Space ) 'Punch!_animator.Animate( "Punch",.2 )Else If Keyboard.KeyDown( Key.Up ) 'walk_animator.Animate( "Walk",1)Man.MoveZ(0.2, True)Else If Keyboard.KeyDown( Key.Down )_animator.Animate( "Walk",1)Man.MoveZ(-0.2, True)'This is the section that I need help with. When I rotate the man 90 degrees'the controls change.Else If Keyboard.KeyDown( Key.Right) 'walk_animator.Animate( "Walk",1)Man.RotateY(-1, True)Else If Keyboard.KeyDown( Key.Left )_animator.Animate( "Walk",1)Man.RotateY(1, True)Else 'idle_animator.Animate( "Idle",.2 )EndifEndif_scene.Update()_camera.Render( canvas )canvas.Scale(800,600)EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()End -
AuthorPosts
You must be logged in to reply to this topic.