From e7aa37fe757151e9e241728c628dde6ccb3e0c07 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 3 May 2015 22:37:10 -0300 Subject: improved kinematic motion, improved demos for kinematic motion --- scene/2d/physics_body_2d.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'scene/2d/physics_body_2d.cpp') diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 6fb798714f..9fd4a25e7f 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -925,6 +925,19 @@ Variant KinematicBody2D::_get_collider() const { return obj; } +void KinematicBody2D::revert_motion() { + + Matrix32 gt = get_global_transform(); + gt.elements[2]-=travel; + travel=Vector2(); + set_global_transform(gt); + +} + +Vector2 KinematicBody2D::get_travel() const { + + return travel; +} Vector2 KinematicBody2D::move(const Vector2& p_motion) { @@ -942,6 +955,7 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) { Matrix32 gt = get_global_transform(); gt.elements[2]+=result.motion; set_global_transform(gt); + travel=result.motion; return result.remainder; #else @@ -1173,6 +1187,8 @@ void KinematicBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("move_to","position"),&KinematicBody2D::move_to); ObjectTypeDB::bind_method(_MD("test_move","rel_vec"),&KinematicBody2D::test_move); + ObjectTypeDB::bind_method(_MD("get_travel"),&KinematicBody2D::get_travel); + ObjectTypeDB::bind_method(_MD("revert_motion"),&KinematicBody2D::revert_motion); ObjectTypeDB::bind_method(_MD("is_colliding"),&KinematicBody2D::is_colliding); -- cgit v1.2.3