def postUpdate(self): planet = Point3.zero() normal = Vec3(self.playernp.getX() - planet.getX(), self.playernp.getY() - planet.getY(), self.playernp.getZ() - planet.getZ()) normal.normalize() fwd = render.getRelativePoint(self.playernp, Vec3(0, 1, 0)) self.playernp.headsUp(fwd, normal) self.__currentPos = self.playernp.getPos() #player movement #space physcis #speed = self.playernp.node().getLinearVelocity() #normal physcis speed = Vec3(0, 0, 0) omega = 0.0 v = 5.8 if inputState.isSet('forward'): speed.setY(v) if inputState.isSet('reverse'): speed.setY(-v) if inputState.isSet('left'): speed.setX(-v) if inputState.isSet('right'): speed.setX(v) if inputState.isSet('flyUp'): speed.setZ(2.0) if inputState.isSet('flyDown'): speed.setZ(-2.0) if inputState.isSet('turnLeft'): omega = 40.0 if inputState.isSet('turnRight'): omega = -40.0 self.playernp.setH(self.playernp, omega * globalClock.getDt()) globalVel = self.playernp.getQuat(render).xform( speed) * globalClock.getDt() normalVel = Vec3(globalVel) normalVel.normalize() if globalVel != Vec3(): globalVelDir = Vec3(globalVel) globalVelDir.normalize() fn = Vec3(0.0, 0.0, 0.0) fn.normalize() velDot = 1.0 - globalVelDir.angleDeg(fn) / 180.0 if velDot < 0.5: self.__currentPos -= Vec3(fn.x * globalVel.x, fn.y * globalVel.y, globalVel.z * globalVel.y) * velDot globalVel *= velDot self.__currentPos += globalVel self.playernp.setPos(self.__currentPos)
def postUpdate(self): planet = Point3.zero() normal = Vec3(self.playernp.getX() - planet.getX(), self.playernp.getY() - planet.getY(), self.playernp.getZ() - planet.getZ()) normal.normalize() fwd = render.getRelativePoint(self.playernp, Vec3(0, 1, 0)) self.playernp.headsUp(fwd, normal) self.__currentPos = self.playernp.getPos() #player movement #space physcis #speed = self.playernp.node().getLinearVelocity() #normal physcis speed = Vec3(0, 0, 0) omega = 0.0 v = 5.8 if inputState.isSet('forward'): speed.setY(v) if inputState.isSet('reverse'): speed.setY(-v) if inputState.isSet('left'): speed.setX(-v) if inputState.isSet('right'): speed.setX(v) if inputState.isSet('flyUp'): speed.setZ( 2.0) if inputState.isSet('flyDown'): speed.setZ( -2.0) if inputState.isSet('turnLeft'): omega = 40.0 if inputState.isSet('turnRight'): omega = -40.0 self.playernp.setH(self.playernp, omega * globalClock.getDt()) globalVel = self.playernp.getQuat(render).xform(speed) * globalClock.getDt() normalVel = Vec3(globalVel) normalVel.normalize() if globalVel != Vec3(): globalVelDir = Vec3(globalVel) globalVelDir.normalize() fn = Vec3(0.0, 0.0, 0.0) fn.normalize() velDot = 1.0 - globalVelDir.angleDeg(fn) / 180.0 if velDot < 0.5: self.__currentPos -= Vec3(fn.x * globalVel.x, fn.y * globalVel.y, globalVel.z * globalVel.y) * velDot globalVel *= velDot self.__currentPos += globalVel self.playernp.setPos(self.__currentPos)
def __init__(self, distributed_object: Character, host: PastryClient): self.host = proxy(host) # Save the actual game object to this instance self.do = distributed_object self.do.avatar = proxy(self) print(self.do.destination) # TODO: Make this the keyframe beginning initial_position = Point3.zero() # TODO: Make into a list of keyframes to do waypoints # TODO: And this kind of info should live on the DO self.start_kf = Keyframe(initial_position, time=now()) self.end_kf = Keyframe(initial_position, time=now()) # show where the avatar is headed TODO: Use an arrow or something? self._marker = base.loader.loadModel('models/Sinbad') self._marker.reparentTo(base.render) self._marker.setScale(.05, .05, .05) super().__init__()
def update(self): # Apply gravity gravity = Point3.zero() - self.playernp.getPos() gravity.normalize() gravity *= G * M * m / (R**2) self.playernp.node().applyCentralForce(gravity)
def __init__(self, mass=1, location = Point3.zero(), velocity=Vec3.zero(), acceleration=Vec3.zero()): # instance variables self.mass = mass self.location = location self.velocity = velocity self.acceleration = acceleration
def update(self): # Apply gravity gravity = Point3.zero() - self.playernp.getPos() gravity.normalize() gravity *= G * M * m / (R ** 2) self.playernp.node().applyCentralForce(gravity)