Skip to content

Commit 027d160

Browse files
authored
Added the apply_torque and set_angular_velocity wrapper (#2838)
Co-authored-by: Stephan <stephan dot felber at tuwien dot ac dot at>
1 parent a557053 commit 027d160

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

arcade/pymunk_physics_engine.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,40 @@ def apply_force(self, sprite: Sprite, force: tuple[float, float]):
702702
)
703703
physics_object.body.apply_force_at_local_point(force, (0, 0))
704704

705+
def apply_torque(self, sprite: Sprite, torque: float):
706+
"""
707+
Apply torque to a Sprite.
708+
709+
Args:
710+
sprite:
711+
The sprite to apply the force to.
712+
torque:
713+
The torque to apply to the sprite.
714+
"""
715+
physics_object = self.sprites[sprite]
716+
if physics_object.body is None:
717+
raise PymunkException(
718+
"Tried to apply a torque, but this physics object has no 'body' set."
719+
)
720+
physics_object.body.torque = torque
721+
722+
def set_angular_velocity(self, sprite: Sprite, velocity: float):
723+
"""
724+
Set velocity to a Sprite.
725+
726+
Args:
727+
sprite:
728+
The sprite to set the angular velocity of.
729+
velocity:
730+
The velocity to set.
731+
"""
732+
physics_object = self.sprites[sprite]
733+
if physics_object.body is None:
734+
raise PymunkException(
735+
"Tried to set velocity, but this physics object has no 'body' set."
736+
)
737+
physics_object.body.angular_velocity = velocity
738+
705739
def set_horizontal_velocity(self, sprite: Sprite, velocity: float) -> None:
706740
"""
707741
Set a sprite's velocity.

0 commit comments

Comments
 (0)