MCPcopy Index your code
hub / github.com/fogleman/Minecraft / get_motion_vector

Method get_motion_vector

main.py:522–559  ·  view source on GitHub ↗

Returns the current motion vector indicating the velocity of the player. Returns ------- vector : tuple of len 3 Tuple containing the velocity in x, y, and z respectively.

(self)

Source from the content-addressed store, hash-verified

520 return (dx, dy, dz)
521
522 def get_motion_vector(self):
523 """ Returns the current motion vector indicating the velocity of the
524 player.
525
526 Returns
527 -------
528 vector : tuple of len 3
529 Tuple containing the velocity in x, y, and z respectively.
530
531 """
532 if any(self.strafe):
533 x, y = self.rotation
534 strafe = math.degrees(math.atan2(*self.strafe))
535 y_angle = math.radians(y)
536 x_angle = math.radians(x + strafe)
537 if self.flying:
538 m = math.cos(y_angle)
539 dy = math.sin(y_angle)
540 if self.strafe[1]:
541 # Moving left or right.
542 dy = 0.0
543 m = 1
544 if self.strafe[0] > 0:
545 # Moving backwards.
546 dy *= -1
547 # When you are flying up or down, you have less left and right
548 # motion.
549 dx = math.cos(x_angle) * m
550 dz = math.sin(x_angle) * m
551 else:
552 dy = 0.0
553 dx = math.cos(x_angle)
554 dz = math.sin(x_angle)
555 else:
556 dy = 0.0
557 dx = 0.0
558 dz = 0.0
559 return (dx, dy, dz)
560
561 def update(self, dt):
562 """ This method is scheduled to be called repeatedly by the pyglet

Callers 1

_updateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected