1 /** 2 A body that is controlled by the 2D physics engine. 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.rigidbody2d; 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.physicsbody2d; 24 import godot.physics2ddirectbodystate; 25 import godot.physicsmaterial; 26 import godot.physics2dtestmotionresult; 27 import godot.collisionobject2d; 28 import godot.node2d; 29 import godot.canvasitem; 30 import godot.node; 31 /** 32 A body that is controlled by the 2D physics engine. 33 34 This node implements simulated 2D physics. You do not control a RigidBody2D directly. Instead you apply forces to it (gravity, impulses, etc.) and the physics simulation calculates the resulting movement based on its mass, friction, and other physical properties. 35 A RigidBody2D has 4 behavior $(D mode)s: Rigid, Static, Character, and Kinematic. 36 $(B Note:) You should not change a RigidBody2D's `position` or `linear_velocity` every frame or even very often. If you need to directly affect the body's state, use $(D _integrateForces), which allows you to directly access the physics state. 37 If you need to override the default physics behavior, you can write a custom force integration. See $(D customIntegrator). 38 */ 39 @GodotBaseClass struct RigidBody2D 40 { 41 enum string _GODOT_internal_name = "RigidBody2D"; 42 public: 43 @nogc nothrow: 44 union { godot_object _godot_object; PhysicsBody2D _GODOT_base; } 45 alias _GODOT_base this; 46 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 47 package(godot) __gshared bool _classBindingInitialized = false; 48 package(godot) static struct _classBinding 49 { 50 __gshared: 51 @GodotName("_integrate_forces") GodotMethod!(void, Physics2DDirectBodyState) _integrateForces; 52 @GodotName("set_mode") GodotMethod!(void, long) setMode; 53 @GodotName("get_mode") GodotMethod!(RigidBody2D.Mode) getMode; 54 @GodotName("set_mass") GodotMethod!(void, double) setMass; 55 @GodotName("get_mass") GodotMethod!(double) getMass; 56 @GodotName("get_inertia") GodotMethod!(double) getInertia; 57 @GodotName("set_inertia") GodotMethod!(void, double) setInertia; 58 @GodotName("set_weight") GodotMethod!(void, double) setWeight; 59 @GodotName("get_weight") GodotMethod!(double) getWeight; 60 @GodotName("set_friction") GodotMethod!(void, double) setFriction; 61 @GodotName("get_friction") GodotMethod!(double) getFriction; 62 @GodotName("set_bounce") GodotMethod!(void, double) setBounce; 63 @GodotName("get_bounce") GodotMethod!(double) getBounce; 64 @GodotName("set_physics_material_override") GodotMethod!(void, PhysicsMaterial) setPhysicsMaterialOverride; 65 @GodotName("get_physics_material_override") GodotMethod!(PhysicsMaterial) getPhysicsMaterialOverride; 66 @GodotName("_reload_physics_characteristics") GodotMethod!(void) _reloadPhysicsCharacteristics; 67 @GodotName("set_gravity_scale") GodotMethod!(void, double) setGravityScale; 68 @GodotName("get_gravity_scale") GodotMethod!(double) getGravityScale; 69 @GodotName("set_linear_damp") GodotMethod!(void, double) setLinearDamp; 70 @GodotName("get_linear_damp") GodotMethod!(double) getLinearDamp; 71 @GodotName("set_angular_damp") GodotMethod!(void, double) setAngularDamp; 72 @GodotName("get_angular_damp") GodotMethod!(double) getAngularDamp; 73 @GodotName("set_linear_velocity") GodotMethod!(void, Vector2) setLinearVelocity; 74 @GodotName("get_linear_velocity") GodotMethod!(Vector2) getLinearVelocity; 75 @GodotName("set_angular_velocity") GodotMethod!(void, double) setAngularVelocity; 76 @GodotName("get_angular_velocity") GodotMethod!(double) getAngularVelocity; 77 @GodotName("set_max_contacts_reported") GodotMethod!(void, long) setMaxContactsReported; 78 @GodotName("get_max_contacts_reported") GodotMethod!(long) getMaxContactsReported; 79 @GodotName("set_use_custom_integrator") GodotMethod!(void, bool) setUseCustomIntegrator; 80 @GodotName("is_using_custom_integrator") GodotMethod!(bool) isUsingCustomIntegrator; 81 @GodotName("set_contact_monitor") GodotMethod!(void, bool) setContactMonitor; 82 @GodotName("is_contact_monitor_enabled") GodotMethod!(bool) isContactMonitorEnabled; 83 @GodotName("set_continuous_collision_detection_mode") GodotMethod!(void, long) setContinuousCollisionDetectionMode; 84 @GodotName("get_continuous_collision_detection_mode") GodotMethod!(RigidBody2D.CCDMode) getContinuousCollisionDetectionMode; 85 @GodotName("set_axis_velocity") GodotMethod!(void, Vector2) setAxisVelocity; 86 @GodotName("apply_central_impulse") GodotMethod!(void, Vector2) applyCentralImpulse; 87 @GodotName("apply_impulse") GodotMethod!(void, Vector2, Vector2) applyImpulse; 88 @GodotName("apply_torque_impulse") GodotMethod!(void, double) applyTorqueImpulse; 89 @GodotName("set_applied_force") GodotMethod!(void, Vector2) setAppliedForce; 90 @GodotName("get_applied_force") GodotMethod!(Vector2) getAppliedForce; 91 @GodotName("set_applied_torque") GodotMethod!(void, double) setAppliedTorque; 92 @GodotName("get_applied_torque") GodotMethod!(double) getAppliedTorque; 93 @GodotName("add_central_force") GodotMethod!(void, Vector2) addCentralForce; 94 @GodotName("add_force") GodotMethod!(void, Vector2, Vector2) addForce; 95 @GodotName("add_torque") GodotMethod!(void, double) addTorque; 96 @GodotName("set_sleeping") GodotMethod!(void, bool) setSleeping; 97 @GodotName("is_sleeping") GodotMethod!(bool) isSleeping; 98 @GodotName("set_can_sleep") GodotMethod!(void, bool) setCanSleep; 99 @GodotName("is_able_to_sleep") GodotMethod!(bool) isAbleToSleep; 100 @GodotName("test_motion") GodotMethod!(bool, Vector2, bool, double, Physics2DTestMotionResult) testMotion; 101 @GodotName("_direct_state_changed") GodotMethod!(void, GodotObject) _directStateChanged; 102 @GodotName("_body_enter_tree") GodotMethod!(void, long) _bodyEnterTree; 103 @GodotName("_body_exit_tree") GodotMethod!(void, long) _bodyExitTree; 104 @GodotName("get_colliding_bodies") GodotMethod!(Array) getCollidingBodies; 105 } 106 bool opEquals(in RigidBody2D other) const { return _godot_object.ptr is other._godot_object.ptr; } 107 RigidBody2D opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 108 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 109 mixin baseCasts; 110 static RigidBody2D _new() 111 { 112 static godot_class_constructor constructor; 113 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("RigidBody2D"); 114 if(constructor is null) return typeof(this).init; 115 return cast(RigidBody2D)(constructor()); 116 } 117 @disable new(size_t s); 118 /// 119 enum Mode : int 120 { 121 /** 122 Rigid mode. The body behaves as a physical object. It collides with other bodies and responds to forces applied to it. This is the default mode. 123 */ 124 modeRigid = 0, 125 /** 126 Static mode. The body behaves like a $(D StaticBody2D) and does not move. 127 */ 128 modeStatic = 1, 129 /** 130 Character mode. Similar to `MODE_RIGID`, but the body can not rotate. 131 */ 132 modeCharacter = 2, 133 /** 134 Kinematic mode. The body behaves like a $(D KinematicBody2D), and must be moved by code. 135 */ 136 modeKinematic = 3, 137 } 138 /// 139 enum CCDMode : int 140 { 141 /** 142 Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects. 143 */ 144 ccdModeDisabled = 0, 145 /** 146 Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise. 147 */ 148 ccdModeCastRay = 1, 149 /** 150 Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise. 151 */ 152 ccdModeCastShape = 2, 153 } 154 /// 155 enum Constants : int 156 { 157 ccdModeDisabled = 0, 158 modeRigid = 0, 159 modeStatic = 1, 160 ccdModeCastRay = 1, 161 ccdModeCastShape = 2, 162 modeCharacter = 2, 163 modeKinematic = 3, 164 } 165 /** 166 Allows you to read and safely modify the simulation state for the object. Use this instead of $(D Node._physics_process) if you need to directly change the body's `position` or other physics properties. By default it works in addition to the usual physics behavior, but $(D customIntegrator) allows you to disable the default behavior and write custom force integration for a body. 167 */ 168 void _integrateForces(Physics2DDirectBodyState state) 169 { 170 Array _GODOT_args = Array.empty_array; 171 _GODOT_args.append(state); 172 String _GODOT_method_name = String("_integrate_forces"); 173 this.callv(_GODOT_method_name, _GODOT_args); 174 } 175 /** 176 177 */ 178 void setMode(in long mode) 179 { 180 checkClassBinding!(typeof(this))(); 181 ptrcall!(void)(_classBinding.setMode, _godot_object, mode); 182 } 183 /** 184 185 */ 186 RigidBody2D.Mode getMode() const 187 { 188 checkClassBinding!(typeof(this))(); 189 return ptrcall!(RigidBody2D.Mode)(_classBinding.getMode, _godot_object); 190 } 191 /** 192 193 */ 194 void setMass(in double mass) 195 { 196 checkClassBinding!(typeof(this))(); 197 ptrcall!(void)(_classBinding.setMass, _godot_object, mass); 198 } 199 /** 200 201 */ 202 double getMass() const 203 { 204 checkClassBinding!(typeof(this))(); 205 return ptrcall!(double)(_classBinding.getMass, _godot_object); 206 } 207 /** 208 209 */ 210 double getInertia() const 211 { 212 checkClassBinding!(typeof(this))(); 213 return ptrcall!(double)(_classBinding.getInertia, _godot_object); 214 } 215 /** 216 217 */ 218 void setInertia(in double inertia) 219 { 220 checkClassBinding!(typeof(this))(); 221 ptrcall!(void)(_classBinding.setInertia, _godot_object, inertia); 222 } 223 /** 224 225 */ 226 void setWeight(in double weight) 227 { 228 checkClassBinding!(typeof(this))(); 229 ptrcall!(void)(_classBinding.setWeight, _godot_object, weight); 230 } 231 /** 232 233 */ 234 double getWeight() const 235 { 236 checkClassBinding!(typeof(this))(); 237 return ptrcall!(double)(_classBinding.getWeight, _godot_object); 238 } 239 /** 240 241 */ 242 void setFriction(in double friction) 243 { 244 checkClassBinding!(typeof(this))(); 245 ptrcall!(void)(_classBinding.setFriction, _godot_object, friction); 246 } 247 /** 248 249 */ 250 double getFriction() const 251 { 252 checkClassBinding!(typeof(this))(); 253 return ptrcall!(double)(_classBinding.getFriction, _godot_object); 254 } 255 /** 256 257 */ 258 void setBounce(in double bounce) 259 { 260 checkClassBinding!(typeof(this))(); 261 ptrcall!(void)(_classBinding.setBounce, _godot_object, bounce); 262 } 263 /** 264 265 */ 266 double getBounce() const 267 { 268 checkClassBinding!(typeof(this))(); 269 return ptrcall!(double)(_classBinding.getBounce, _godot_object); 270 } 271 /** 272 273 */ 274 void setPhysicsMaterialOverride(PhysicsMaterial physics_material_override) 275 { 276 checkClassBinding!(typeof(this))(); 277 ptrcall!(void)(_classBinding.setPhysicsMaterialOverride, _godot_object, physics_material_override); 278 } 279 /** 280 281 */ 282 Ref!PhysicsMaterial getPhysicsMaterialOverride() const 283 { 284 checkClassBinding!(typeof(this))(); 285 return ptrcall!(PhysicsMaterial)(_classBinding.getPhysicsMaterialOverride, _godot_object); 286 } 287 /** 288 289 */ 290 void _reloadPhysicsCharacteristics() 291 { 292 Array _GODOT_args = Array.empty_array; 293 String _GODOT_method_name = String("_reload_physics_characteristics"); 294 this.callv(_GODOT_method_name, _GODOT_args); 295 } 296 /** 297 298 */ 299 void setGravityScale(in double gravity_scale) 300 { 301 checkClassBinding!(typeof(this))(); 302 ptrcall!(void)(_classBinding.setGravityScale, _godot_object, gravity_scale); 303 } 304 /** 305 306 */ 307 double getGravityScale() const 308 { 309 checkClassBinding!(typeof(this))(); 310 return ptrcall!(double)(_classBinding.getGravityScale, _godot_object); 311 } 312 /** 313 314 */ 315 void setLinearDamp(in double linear_damp) 316 { 317 checkClassBinding!(typeof(this))(); 318 ptrcall!(void)(_classBinding.setLinearDamp, _godot_object, linear_damp); 319 } 320 /** 321 322 */ 323 double getLinearDamp() const 324 { 325 checkClassBinding!(typeof(this))(); 326 return ptrcall!(double)(_classBinding.getLinearDamp, _godot_object); 327 } 328 /** 329 330 */ 331 void setAngularDamp(in double angular_damp) 332 { 333 checkClassBinding!(typeof(this))(); 334 ptrcall!(void)(_classBinding.setAngularDamp, _godot_object, angular_damp); 335 } 336 /** 337 338 */ 339 double getAngularDamp() const 340 { 341 checkClassBinding!(typeof(this))(); 342 return ptrcall!(double)(_classBinding.getAngularDamp, _godot_object); 343 } 344 /** 345 346 */ 347 void setLinearVelocity(in Vector2 linear_velocity) 348 { 349 checkClassBinding!(typeof(this))(); 350 ptrcall!(void)(_classBinding.setLinearVelocity, _godot_object, linear_velocity); 351 } 352 /** 353 354 */ 355 Vector2 getLinearVelocity() const 356 { 357 checkClassBinding!(typeof(this))(); 358 return ptrcall!(Vector2)(_classBinding.getLinearVelocity, _godot_object); 359 } 360 /** 361 362 */ 363 void setAngularVelocity(in double angular_velocity) 364 { 365 checkClassBinding!(typeof(this))(); 366 ptrcall!(void)(_classBinding.setAngularVelocity, _godot_object, angular_velocity); 367 } 368 /** 369 370 */ 371 double getAngularVelocity() const 372 { 373 checkClassBinding!(typeof(this))(); 374 return ptrcall!(double)(_classBinding.getAngularVelocity, _godot_object); 375 } 376 /** 377 378 */ 379 void setMaxContactsReported(in long amount) 380 { 381 checkClassBinding!(typeof(this))(); 382 ptrcall!(void)(_classBinding.setMaxContactsReported, _godot_object, amount); 383 } 384 /** 385 386 */ 387 long getMaxContactsReported() const 388 { 389 checkClassBinding!(typeof(this))(); 390 return ptrcall!(long)(_classBinding.getMaxContactsReported, _godot_object); 391 } 392 /** 393 394 */ 395 void setUseCustomIntegrator(in bool enable) 396 { 397 checkClassBinding!(typeof(this))(); 398 ptrcall!(void)(_classBinding.setUseCustomIntegrator, _godot_object, enable); 399 } 400 /** 401 402 */ 403 bool isUsingCustomIntegrator() 404 { 405 checkClassBinding!(typeof(this))(); 406 return ptrcall!(bool)(_classBinding.isUsingCustomIntegrator, _godot_object); 407 } 408 /** 409 410 */ 411 void setContactMonitor(in bool enabled) 412 { 413 checkClassBinding!(typeof(this))(); 414 ptrcall!(void)(_classBinding.setContactMonitor, _godot_object, enabled); 415 } 416 /** 417 418 */ 419 bool isContactMonitorEnabled() const 420 { 421 checkClassBinding!(typeof(this))(); 422 return ptrcall!(bool)(_classBinding.isContactMonitorEnabled, _godot_object); 423 } 424 /** 425 426 */ 427 void setContinuousCollisionDetectionMode(in long mode) 428 { 429 checkClassBinding!(typeof(this))(); 430 ptrcall!(void)(_classBinding.setContinuousCollisionDetectionMode, _godot_object, mode); 431 } 432 /** 433 434 */ 435 RigidBody2D.CCDMode getContinuousCollisionDetectionMode() const 436 { 437 checkClassBinding!(typeof(this))(); 438 return ptrcall!(RigidBody2D.CCDMode)(_classBinding.getContinuousCollisionDetectionMode, _godot_object); 439 } 440 /** 441 Sets the body's velocity on the given axis. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior. 442 */ 443 void setAxisVelocity(in Vector2 axis_velocity) 444 { 445 checkClassBinding!(typeof(this))(); 446 ptrcall!(void)(_classBinding.setAxisVelocity, _godot_object, axis_velocity); 447 } 448 /** 449 Applies a directional impulse without affecting rotation. 450 */ 451 void applyCentralImpulse(in Vector2 impulse) 452 { 453 checkClassBinding!(typeof(this))(); 454 ptrcall!(void)(_classBinding.applyCentralImpulse, _godot_object, impulse); 455 } 456 /** 457 Applies a positioned impulse to the body (which will be affected by the body mass and shape). This is the equivalent of hitting a billiard ball with a cue: a force that is applied instantaneously. Both the impulse and the offset from the body origin are in global coordinates. 458 */ 459 void applyImpulse(in Vector2 offset, in Vector2 impulse) 460 { 461 checkClassBinding!(typeof(this))(); 462 ptrcall!(void)(_classBinding.applyImpulse, _godot_object, offset, impulse); 463 } 464 /** 465 Applies a rotational impulse to the body. 466 */ 467 void applyTorqueImpulse(in double torque) 468 { 469 checkClassBinding!(typeof(this))(); 470 ptrcall!(void)(_classBinding.applyTorqueImpulse, _godot_object, torque); 471 } 472 /** 473 474 */ 475 void setAppliedForce(in Vector2 force) 476 { 477 checkClassBinding!(typeof(this))(); 478 ptrcall!(void)(_classBinding.setAppliedForce, _godot_object, force); 479 } 480 /** 481 482 */ 483 Vector2 getAppliedForce() const 484 { 485 checkClassBinding!(typeof(this))(); 486 return ptrcall!(Vector2)(_classBinding.getAppliedForce, _godot_object); 487 } 488 /** 489 490 */ 491 void setAppliedTorque(in double torque) 492 { 493 checkClassBinding!(typeof(this))(); 494 ptrcall!(void)(_classBinding.setAppliedTorque, _godot_object, torque); 495 } 496 /** 497 498 */ 499 double getAppliedTorque() const 500 { 501 checkClassBinding!(typeof(this))(); 502 return ptrcall!(double)(_classBinding.getAppliedTorque, _godot_object); 503 } 504 /** 505 Adds a constant directional force without affecting rotation. 506 */ 507 void addCentralForce(in Vector2 force) 508 { 509 checkClassBinding!(typeof(this))(); 510 ptrcall!(void)(_classBinding.addCentralForce, _godot_object, force); 511 } 512 /** 513 Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates. 514 */ 515 void addForce(in Vector2 offset, in Vector2 force) 516 { 517 checkClassBinding!(typeof(this))(); 518 ptrcall!(void)(_classBinding.addForce, _godot_object, offset, force); 519 } 520 /** 521 Adds a constant rotational force. 522 */ 523 void addTorque(in double torque) 524 { 525 checkClassBinding!(typeof(this))(); 526 ptrcall!(void)(_classBinding.addTorque, _godot_object, torque); 527 } 528 /** 529 530 */ 531 void setSleeping(in bool sleeping) 532 { 533 checkClassBinding!(typeof(this))(); 534 ptrcall!(void)(_classBinding.setSleeping, _godot_object, sleeping); 535 } 536 /** 537 538 */ 539 bool isSleeping() const 540 { 541 checkClassBinding!(typeof(this))(); 542 return ptrcall!(bool)(_classBinding.isSleeping, _godot_object); 543 } 544 /** 545 546 */ 547 void setCanSleep(in bool able_to_sleep) 548 { 549 checkClassBinding!(typeof(this))(); 550 ptrcall!(void)(_classBinding.setCanSleep, _godot_object, able_to_sleep); 551 } 552 /** 553 554 */ 555 bool isAbleToSleep() const 556 { 557 checkClassBinding!(typeof(this))(); 558 return ptrcall!(bool)(_classBinding.isAbleToSleep, _godot_object); 559 } 560 /** 561 Returns `true` if a collision would result from moving in the given vector. `margin` increases the size of the shapes involved in the collision detection, and `result` is an object of type $(D Physics2DTestMotionResult), which contains additional information about the collision (should there be one). 562 */ 563 bool testMotion(in Vector2 motion, in bool infinite_inertia = true, in double margin = 0.08, Physics2DTestMotionResult result = Physics2DTestMotionResult.init) 564 { 565 checkClassBinding!(typeof(this))(); 566 return ptrcall!(bool)(_classBinding.testMotion, _godot_object, motion, infinite_inertia, margin, result); 567 } 568 /** 569 570 */ 571 void _directStateChanged(GodotObject arg0) 572 { 573 Array _GODOT_args = Array.empty_array; 574 _GODOT_args.append(arg0); 575 String _GODOT_method_name = String("_direct_state_changed"); 576 this.callv(_GODOT_method_name, _GODOT_args); 577 } 578 /** 579 580 */ 581 void _bodyEnterTree(in long arg0) 582 { 583 Array _GODOT_args = Array.empty_array; 584 _GODOT_args.append(arg0); 585 String _GODOT_method_name = String("_body_enter_tree"); 586 this.callv(_GODOT_method_name, _GODOT_args); 587 } 588 /** 589 590 */ 591 void _bodyExitTree(in long arg0) 592 { 593 Array _GODOT_args = Array.empty_array; 594 _GODOT_args.append(arg0); 595 String _GODOT_method_name = String("_body_exit_tree"); 596 this.callv(_GODOT_method_name, _GODOT_args); 597 } 598 /** 599 Returns a list of the bodies colliding with this one. Use $(D contactsReported) to set the maximum number reported. You must also set $(D contactMonitor) to `true`. Note that the result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead. 600 */ 601 Array getCollidingBodies() const 602 { 603 checkClassBinding!(typeof(this))(); 604 return ptrcall!(Array)(_classBinding.getCollidingBodies, _godot_object); 605 } 606 /** 607 The body's mode. See `MODE_*` constants. Default value: `MODE_RIGID`. 608 */ 609 @property RigidBody2D.Mode mode() 610 { 611 return getMode(); 612 } 613 /// ditto 614 @property void mode(long v) 615 { 616 setMode(v); 617 } 618 /** 619 The body's mass. Default value: `1`. 620 */ 621 @property double mass() 622 { 623 return getMass(); 624 } 625 /// ditto 626 @property void mass(double v) 627 { 628 setMass(v); 629 } 630 /** 631 The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this function allows you to set a custom value. Set 0 (or negative) inertia to return to automatically computing it. 632 */ 633 @property double inertia() 634 { 635 return getInertia(); 636 } 637 /// ditto 638 @property void inertia(double v) 639 { 640 setInertia(v); 641 } 642 /** 643 The body's weight based on its mass and the "Default Gravity" value in "Project > Project Settings > Physics > 2d". 644 */ 645 @property double weight() 646 { 647 return getWeight(); 648 } 649 /// ditto 650 @property void weight(double v) 651 { 652 setWeight(v); 653 } 654 /** 655 The body's friction. Values range from `0` (frictionless) to `1` (maximum friction). Default value: `1`. 656 */ 657 @property double friction() 658 { 659 return getFriction(); 660 } 661 /// ditto 662 @property void friction(double v) 663 { 664 setFriction(v); 665 } 666 /** 667 The body's bounciness. Default value: `0`. 668 */ 669 @property double bounce() 670 { 671 return getBounce(); 672 } 673 /// ditto 674 @property void bounce(double v) 675 { 676 setBounce(v); 677 } 678 /** 679 680 */ 681 @property PhysicsMaterial physicsMaterialOverride() 682 { 683 return getPhysicsMaterialOverride(); 684 } 685 /// ditto 686 @property void physicsMaterialOverride(PhysicsMaterial v) 687 { 688 setPhysicsMaterialOverride(v); 689 } 690 /** 691 Multiplies the gravity applied to the body. The body's gravity is calculated from the "Default Gravity" value in "Project > Project Settings > Physics > 2d" and/or any additional gravity vector applied by $(D Area2D)s. Default value: `1`. 692 */ 693 @property double gravityScale() 694 { 695 return getGravityScale(); 696 } 697 /// ditto 698 @property void gravityScale(double v) 699 { 700 setGravityScale(v); 701 } 702 /** 703 If `true` internal force integration is disabled for this body. Aside from collision response, the body will only move as determined by the $(D _integrateForces) function. 704 */ 705 @property bool customIntegrator() 706 { 707 return isUsingCustomIntegrator(); 708 } 709 /// ditto 710 @property void customIntegrator(bool v) 711 { 712 setUseCustomIntegrator(v); 713 } 714 /** 715 Continuous collision detection mode. Default value: `CCD_MODE_DISABLED`. 716 Continuous collision detection tries to predict where a moving body will collide instead of moving it and correcting its movement after collision. Continuous collision detection is slower, but more precise and misses fewer collisions with small, fast-moving objects. Raycasting and shapecasting methods are available. See `CCD_MODE_` constants for details. 717 */ 718 @property RigidBody2D.CCDMode continuousCd() 719 { 720 return getContinuousCollisionDetectionMode(); 721 } 722 /// ditto 723 @property void continuousCd(long v) 724 { 725 setContinuousCollisionDetectionMode(v); 726 } 727 /** 728 The maximum number of contacts to report. Default value: `0`. 729 */ 730 @property long contactsReported() 731 { 732 return getMaxContactsReported(); 733 } 734 /// ditto 735 @property void contactsReported(long v) 736 { 737 setMaxContactsReported(v); 738 } 739 /** 740 If `true` the body will emit signals when it collides with another RigidBody2D. See also $(D contactsReported). Default value: `false`. 741 */ 742 @property bool contactMonitor() 743 { 744 return isContactMonitorEnabled(); 745 } 746 /// ditto 747 @property void contactMonitor(bool v) 748 { 749 setContactMonitor(v); 750 } 751 /** 752 If `true` the body is sleeping and will not calculate forces until woken up by a collision or by using $(D applyImpulse) or $(D addForce). 753 */ 754 @property bool sleeping() 755 { 756 return isSleeping(); 757 } 758 /// ditto 759 @property void sleeping(bool v) 760 { 761 setSleeping(v); 762 } 763 /** 764 If `true` the body will not calculate forces and will act as a static body if there is no movement. The body will wake up when other forces are applied via collisions or by using $(D applyImpulse) or $(D addForce). Default value: `true`. 765 */ 766 @property bool canSleep() 767 { 768 return isAbleToSleep(); 769 } 770 /// ditto 771 @property void canSleep(bool v) 772 { 773 setCanSleep(v); 774 } 775 /** 776 The body's linear velocity. 777 */ 778 @property Vector2 linearVelocity() 779 { 780 return getLinearVelocity(); 781 } 782 /// ditto 783 @property void linearVelocity(Vector2 v) 784 { 785 setLinearVelocity(v); 786 } 787 /** 788 Damps the body's $(D linearVelocity). If `-1` the body will use the "Default Linear Damp" in "Project > Project Settings > Physics > 2d". Default value: `-1`. 789 */ 790 @property double linearDamp() 791 { 792 return getLinearDamp(); 793 } 794 /// ditto 795 @property void linearDamp(double v) 796 { 797 setLinearDamp(v); 798 } 799 /** 800 The body's rotational velocity. 801 */ 802 @property double angularVelocity() 803 { 804 return getAngularVelocity(); 805 } 806 /// ditto 807 @property void angularVelocity(double v) 808 { 809 setAngularVelocity(v); 810 } 811 /** 812 Damps the body's $(D angularVelocity). If `-1` the body will use the "Default Angular Damp" in "Project > Project Settings > Physics > 2d". Default value: `-1`. 813 */ 814 @property double angularDamp() 815 { 816 return getAngularDamp(); 817 } 818 /// ditto 819 @property void angularDamp(double v) 820 { 821 setAngularDamp(v); 822 } 823 /** 824 The body's total applied force. 825 */ 826 @property Vector2 appliedForce() 827 { 828 return getAppliedForce(); 829 } 830 /// ditto 831 @property void appliedForce(Vector2 v) 832 { 833 setAppliedForce(v); 834 } 835 /** 836 The body's total applied torque. 837 */ 838 @property double appliedTorque() 839 { 840 return getAppliedTorque(); 841 } 842 /// ditto 843 @property void appliedTorque(double v) 844 { 845 setAppliedTorque(v); 846 } 847 }