From ff54287a74134716ff69b95a1f117d40aa05599a Mon Sep 17 00:00:00 2001 From: N8n5h <42382648+N8n5h@users.noreply.github.com> Date: Sun, 7 Jul 2019 13:01:35 -0300 Subject: [PATCH 1/2] Update PlayerController.hx --- twin_stick/Sources/arm/PlayerController.hx | 33 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/twin_stick/Sources/arm/PlayerController.hx b/twin_stick/Sources/arm/PlayerController.hx index 79d2bab..de8ae1b 100644 --- a/twin_stick/Sources/arm/PlayerController.hx +++ b/twin_stick/Sources/arm/PlayerController.hx @@ -1,6 +1,10 @@ package arm; import iron.math.Vec4; +import iron.math.Vec2; +import iron.math.RayCaster; +import iron.Scene; +import armory.trait.physics.PhysicsWorld; import iron.object.Object; import iron.object.BoneAnimation; import iron.system.Time; @@ -66,11 +70,19 @@ class PlayerController extends iron.Trait { dir.normalize(); // Mouse control - var mx = -(iron.App.w() / 2 - mouse.x) / iron.App.w(); - var my = (iron.App.h() / 2 - mouse.y) / iron.App.h(); - var mv = new Vec4(mx * 2, my * 2, 0.0); - mv.normalize(); - armature.transform.rot.fromTo(Vec4.yAxis(), mv); + var mouse_pos = new Vec2(mouse.x,mouse.y); + var hit_pos = project_mouse_pos(mouse_pos); + + if (hit_pos != null) + { + var center = new Vec4(hit_pos.x,hit_pos.y,0); + var eye = armature.transform.world.getLoc(); + eye.set(eye.x,eye.y,0); + + var target = center.sub(eye); + + armature.transform.rot.fromTo(Vec4.yAxis(), target.normalize()); + } // Gamepad control if (gamepad != null) { @@ -84,6 +96,17 @@ class PlayerController extends iron.Trait { updateBody(); } + function project_mouse_pos(input:Vec2){ + var camera = Scene.active.camera; + + var start = new Vec4(); + var end = new Vec4(); + + var physics = PhysicsWorld.active; + var hit_pos = RayCaster.planeIntersect(Vec4.zAxis(),new Vec4(0,0,1),input.x,input.y,camera); + return hit_pos; + } + function getAngle(va:Vec4, vb:Vec4) { var vn = Vec4.zAxis(); var dot = va.dot(vb); From 803ca9248fe504af09cd1362eb2f50e7fdabceb1 Mon Sep 17 00:00:00 2001 From: N8n5h <42382648+N8n5h@users.noreply.github.com> Date: Sun, 7 Jul 2019 13:14:19 -0300 Subject: [PATCH 2/2] Update PlayerController.hx cleanup, physicWorld was used but didn't end up in the final version.. --- twin_stick/Sources/arm/PlayerController.hx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/twin_stick/Sources/arm/PlayerController.hx b/twin_stick/Sources/arm/PlayerController.hx index de8ae1b..093af71 100644 --- a/twin_stick/Sources/arm/PlayerController.hx +++ b/twin_stick/Sources/arm/PlayerController.hx @@ -4,7 +4,6 @@ import iron.math.Vec4; import iron.math.Vec2; import iron.math.RayCaster; import iron.Scene; -import armory.trait.physics.PhysicsWorld; import iron.object.Object; import iron.object.BoneAnimation; import iron.system.Time; @@ -101,8 +100,7 @@ class PlayerController extends iron.Trait { var start = new Vec4(); var end = new Vec4(); - - var physics = PhysicsWorld.active; + var hit_pos = RayCaster.planeIntersect(Vec4.zAxis(),new Vec4(0,0,1),input.x,input.y,camera); return hit_pos; }