Skip to content

Commit

Permalink
Merge pull request #3 from N8n5h/patch-1
Browse files Browse the repository at this point in the history
Update PlayerController.hx
  • Loading branch information
luboslenco authored Jul 7, 2019
2 parents 4297799 + 803ca92 commit 8fdb8be
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions twin_stick/Sources/arm/PlayerController.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package arm;

import iron.math.Vec4;
import iron.math.Vec2;
import iron.math.RayCaster;
import iron.Scene;
import iron.object.Object;
import iron.object.BoneAnimation;
import iron.system.Time;
Expand Down Expand Up @@ -66,11 +69,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) {
Expand All @@ -84,6 +95,16 @@ 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 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);
Expand Down

0 comments on commit 8fdb8be

Please sign in to comment.