1 /**
2 Kinematic body 3D node.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.kinematicbody;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.physicsbody;
24 import godot.kinematiccollision;
25 import godot.collisionobject;
26 import godot.spatial;
27 import godot.node;
28 /**
29 Kinematic body 3D node.
30 
31 Kinematic bodies are special types of bodies that are meant to be user-controlled. They are not affected by physics at all (to other types of bodies, such a character or a rigid body, these are the same as a static body). They have however, two main uses:
32 Simulated Motion: When these bodies are moved manually, either from code or from an AnimationPlayer (with process mode set to fixed), the physics will automatically compute an estimate of their linear and angular velocity. This makes them very useful for moving platforms or other AnimationPlayer-controlled objects (like a door, a bridge that opens, etc).
33 Kinematic Characters: KinematicBody also has an API for moving objects (the $(D moveAndCollide) and $(D moveAndSlide) methods) while performing collision tests. This makes them really useful to implement characters that collide against a world, but that don't require advanced physics.
34 */
35 @GodotBaseClass struct KinematicBody
36 {
37 	enum string _GODOT_internal_name = "KinematicBody";
38 public:
39 @nogc nothrow:
40 	union { godot_object _godot_object; PhysicsBody _GODOT_base; }
41 	alias _GODOT_base this;
42 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
43 	package(godot) __gshared bool _classBindingInitialized = false;
44 	package(godot) static struct _classBinding
45 	{
46 		__gshared:
47 		@GodotName("move_and_collide") GodotMethod!(KinematicCollision, Vector3, bool, bool) moveAndCollide;
48 		@GodotName("move_and_slide") GodotMethod!(Vector3, Vector3, Vector3, bool, long, double, bool) moveAndSlide;
49 		@GodotName("move_and_slide_with_snap") GodotMethod!(Vector3, Vector3, Vector3, Vector3, bool, bool, long, double) moveAndSlideWithSnap;
50 		@GodotName("test_move") GodotMethod!(bool, Transform, Vector3, bool) testMove;
51 		@GodotName("is_on_floor") GodotMethod!(bool) isOnFloor;
52 		@GodotName("is_on_ceiling") GodotMethod!(bool) isOnCeiling;
53 		@GodotName("is_on_wall") GodotMethod!(bool) isOnWall;
54 		@GodotName("get_floor_velocity") GodotMethod!(Vector3) getFloorVelocity;
55 		@GodotName("set_axis_lock") GodotMethod!(void, long, bool) setAxisLock;
56 		@GodotName("get_axis_lock") GodotMethod!(bool, long) getAxisLock;
57 		@GodotName("set_safe_margin") GodotMethod!(void, double) setSafeMargin;
58 		@GodotName("get_safe_margin") GodotMethod!(double) getSafeMargin;
59 		@GodotName("get_slide_count") GodotMethod!(long) getSlideCount;
60 		@GodotName("get_slide_collision") GodotMethod!(KinematicCollision, long) getSlideCollision;
61 	}
62 	bool opEquals(in KinematicBody other) const { return _godot_object.ptr is other._godot_object.ptr; }
63 	KinematicBody opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
64 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
65 	mixin baseCasts;
66 	static KinematicBody _new()
67 	{
68 		static godot_class_constructor constructor;
69 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("KinematicBody");
70 		if(constructor is null) return typeof(this).init;
71 		return cast(KinematicBody)(constructor());
72 	}
73 	@disable new(size_t s);
74 	/**
75 	Moves the body along the vector `rel_vec`. The body will stop if it collides. Returns a $(D KinematicCollision), which contains information about the collision.
76 	If `test_only` is `true`, the body does not move but the would-be collision information is given.
77 	*/
78 	Ref!KinematicCollision moveAndCollide(in Vector3 rel_vec, in bool infinite_inertia = true, in bool test_only = false)
79 	{
80 		checkClassBinding!(typeof(this))();
81 		return ptrcall!(KinematicCollision)(_classBinding.moveAndCollide, _godot_object, rel_vec, infinite_inertia, test_only);
82 	}
83 	/**
84 	Moves the body along a vector. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a `KinematicBody` or $(D RigidBody), it will also be affected by the motion of the other body. You can use this to make moving or rotating platforms, or to make nodes push other nodes.
85 	`linear_velocity` is a value in pixels per second. Unlike in for example $(D moveAndCollide), you should $(I not) multiply it with `delta` — this is done by the method.
86 	`floor_normal` is the up direction, used to determine what is a wall and what is a floor or a ceiling. If set to the default value of `Vector3(0, 0, 0)`, everything is considered a wall. This is useful for topdown games.
87 	$(I TODO: Update for new stop_on_slode argument.) If the body is standing on a slope and the horizontal speed (relative to the floor's speed) goes below `slope_stop_min_velocity`, the body will stop completely. This prevents the body from sliding down slopes when you include gravity in `linear_velocity`. When set to lower values, the body will not be able to stand still on steep slopes.
88 	If the body collides, it will change direction a maximum of `max_slides` times before it stops.
89 	`floor_max_angle` is the maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall. The default value equals 45 degrees.
90 	Returns the movement that remained when the body stopped. To get more detailed information about collisions that occurred, use $(D getSlideCollision).
91 	*/
92 	Vector3 moveAndSlide(in Vector3 linear_velocity, in Vector3 floor_normal = Vector3(0, 0, 0), in bool stop_on_slope = false, in long max_slides = 4, in double floor_max_angle = 0.785398, in bool infinite_inertia = true)
93 	{
94 		checkClassBinding!(typeof(this))();
95 		return ptrcall!(Vector3)(_classBinding.moveAndSlide, _godot_object, linear_velocity, floor_normal, stop_on_slope, max_slides, floor_max_angle, infinite_inertia);
96 	}
97 	/**
98 	Moves the body while keeping it attached to slopes. Similar to $(D moveAndSlide).
99 	As long as the `snap` vector is in contact with the ground, the body will remain attached to the surface. This means you must disable snap in order to jump, for example. You can do this by setting`snap` to`(0, 0, 0)` or by using $(D moveAndSlide) instead.
100 	*/
101 	Vector3 moveAndSlideWithSnap(in Vector3 linear_velocity, in Vector3 snap, in Vector3 floor_normal = Vector3(0, 0, 0), in bool infinite_inertia = true, in bool stop_on_slope = false, in long max_bounces = 4, in double floor_max_angle = 0.785398)
102 	{
103 		checkClassBinding!(typeof(this))();
104 		return ptrcall!(Vector3)(_classBinding.moveAndSlideWithSnap, _godot_object, linear_velocity, snap, floor_normal, infinite_inertia, stop_on_slope, max_bounces, floor_max_angle);
105 	}
106 	/**
107 	Checks for collisions without moving the body. Virtually sets the node's position, scale and rotation to that of the given $(D Transform), then tries to move the body along the vector `rel_vec`. Returns `true` if a collision would occur.
108 	*/
109 	bool testMove(in Transform from, in Vector3 rel_vec, in bool infinite_inertia)
110 	{
111 		checkClassBinding!(typeof(this))();
112 		return ptrcall!(bool)(_classBinding.testMove, _godot_object, from, rel_vec, infinite_inertia);
113 	}
114 	/**
115 	Returns `true` if the body is on the floor. Only updates when calling $(D moveAndSlide).
116 	*/
117 	bool isOnFloor() const
118 	{
119 		checkClassBinding!(typeof(this))();
120 		return ptrcall!(bool)(_classBinding.isOnFloor, _godot_object);
121 	}
122 	/**
123 	Returns `true` if the body is on the ceiling. Only updates when calling $(D moveAndSlide).
124 	*/
125 	bool isOnCeiling() const
126 	{
127 		checkClassBinding!(typeof(this))();
128 		return ptrcall!(bool)(_classBinding.isOnCeiling, _godot_object);
129 	}
130 	/**
131 	Returns `true` if the body is on a wall. Only updates when calling $(D moveAndSlide).
132 	*/
133 	bool isOnWall() const
134 	{
135 		checkClassBinding!(typeof(this))();
136 		return ptrcall!(bool)(_classBinding.isOnWall, _godot_object);
137 	}
138 	/**
139 	Returns the velocity of the floor. Only updates when calling $(D moveAndSlide).
140 	*/
141 	Vector3 getFloorVelocity() const
142 	{
143 		checkClassBinding!(typeof(this))();
144 		return ptrcall!(Vector3)(_classBinding.getFloorVelocity, _godot_object);
145 	}
146 	/**
147 	
148 	*/
149 	void setAxisLock(in long axis, in bool lock)
150 	{
151 		checkClassBinding!(typeof(this))();
152 		ptrcall!(void)(_classBinding.setAxisLock, _godot_object, axis, lock);
153 	}
154 	/**
155 	
156 	*/
157 	bool getAxisLock(in long axis) const
158 	{
159 		checkClassBinding!(typeof(this))();
160 		return ptrcall!(bool)(_classBinding.getAxisLock, _godot_object, axis);
161 	}
162 	/**
163 	
164 	*/
165 	void setSafeMargin(in double pixels)
166 	{
167 		checkClassBinding!(typeof(this))();
168 		ptrcall!(void)(_classBinding.setSafeMargin, _godot_object, pixels);
169 	}
170 	/**
171 	
172 	*/
173 	double getSafeMargin() const
174 	{
175 		checkClassBinding!(typeof(this))();
176 		return ptrcall!(double)(_classBinding.getSafeMargin, _godot_object);
177 	}
178 	/**
179 	Returns the number of times the body collided and changed direction during the last call to $(D moveAndSlide).
180 	*/
181 	long getSlideCount() const
182 	{
183 		checkClassBinding!(typeof(this))();
184 		return ptrcall!(long)(_classBinding.getSlideCount, _godot_object);
185 	}
186 	/**
187 	Returns a $(D KinematicCollision), which contains information about a collision that occurred during the last $(D moveAndSlide) call. Since the body can collide several times in a single call to $(D moveAndSlide), you must specify the index of the collision in the range 0 to ($(D getSlideCount) - 1).
188 	*/
189 	Ref!KinematicCollision getSlideCollision(in long slide_idx)
190 	{
191 		checkClassBinding!(typeof(this))();
192 		return ptrcall!(KinematicCollision)(_classBinding.getSlideCollision, _godot_object, slide_idx);
193 	}
194 	/**
195 	
196 	*/
197 	@property bool moveLockX()
198 	{
199 		return getAxisLock(1);
200 	}
201 	/// ditto
202 	@property void moveLockX(bool v)
203 	{
204 		setAxisLock(1, v);
205 	}
206 	/**
207 	
208 	*/
209 	@property bool moveLockY()
210 	{
211 		return getAxisLock(2);
212 	}
213 	/// ditto
214 	@property void moveLockY(bool v)
215 	{
216 		setAxisLock(2, v);
217 	}
218 	/**
219 	
220 	*/
221 	@property bool moveLockZ()
222 	{
223 		return getAxisLock(4);
224 	}
225 	/// ditto
226 	@property void moveLockZ(bool v)
227 	{
228 		setAxisLock(4, v);
229 	}
230 	/**
231 	If the body is at least this close to another body, this body will consider them to be colliding.
232 	*/
233 	@property double collisionSafeMargin()
234 	{
235 		return getSafeMargin();
236 	}
237 	/// ditto
238 	@property void collisionSafeMargin(double v)
239 	{
240 		setSafeMargin(v);
241 	}
242 }