Wednesday, September 30, 2026
HomeiOS DevelopmentHow do I implement a bodily physique node that enables the participant...

How do I implement a bodily physique node that enables the participant to maneuver left and proper with out stopping when the route is modified?

[ad_1]

Intro

  • I’ve a view the place the bounds for a bodily physique is 0 from the highest, left, and proper. For the underside, the boundary for my physique is the highest of my floor.
    • EX: my display screen is 1024×768 and my floor has a peak of 64 so my physics physique is
      self.physicsBody = SKPhysicsBody(edgeLoopFrom: body.inset(by: UIEdgeInsets(prime: 64, left: 0, backside: 0, proper: 0)))
  • My participant measurement is 64×64
    • My gamers physics physique is participant.physicsBody = SKPhysicsBody(texture: participant.texture! , measurement: participant.measurement)
    • The Participant is spawned onto of the bottom
  • I’ve created swipe gestures to constantly transfer within the route of the swipe
  • Assume that the best way my categoryBitMasks, for each participant and floor, are assigned correctly
    • I’ve the contactTest and collision bit masks for the participant assigned to the bottom class bit masks
    • Once I detect a collision (when the participant hits the ceiling, floor, and the aspect partitions) the vector motion of the participant cease

Drawback I’m going through

  • When the participant is "standing" on the bottom and strikes left, once I swipe it to maneuver the opposite route, I’ve to create a brand new bodily physique precisely the identical properties as the unique, aside from the feel. I’ve to do this as a result of my participant texture will not be symmetrical, due to this fact altering the feel of the physics physique.
    • NOTE: if the participant is already going through/going within the route of the swipe, it doesn’t get a brand new bodily physique
  • As soon as the route of the participant is modified, Xcode detects it as a collision and stops the motion which then requires me to swipe once more in that very same route to be able to transfer once more.
    • The motion is stopped as a result of in my didBegan func, a participant ought to cease motion when colliding with the bounds in order that it does not exit of the display screen
      This is a demo
  • Attributable to my laptop computer not highly effective sufficient to deal with working the simulator and recording it on the identical time, there’s somewhat lag. However what is occurring is that I’m swiping proper, the character strikes proper, then I swipe left, and the character does not transfer in any respect till I swipe left once more.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments