1

I have tried creating bitmask categories, setting all restitution values to 1 and everything else under the sun including running the application an a device and it still is not working at all. After setting an SKSpriteNode with retitution 1 to hit another skspritenode also with restitution one at dx: 100, it still doesn't bounce! Here is my code for GameScene.swift:

import SpriteKit
import GameplayKit

class GameScene: SKScene {

override func didMove(to view: SKView) {

    let Ball = SKSpriteNode()
    Ball.self.childNode(withName: "Ball")

    let playerPaddle = SKSpriteNode()
    playerPaddle.self.childNode(withName: "playerPaddle")

    let computerPaddle = SKSpriteNode()
    computerPaddle.self.childNode(withName: "computerPaddle")

    let ballCategory: UInt32 = 0x1 << 1
    let paddleCategory: UInt32 = 0x1 << 2
    let borderCategory: UInt32 = 0x1 << 3

    Ball.physicsBody?.categoryBitMask = ballCategory
    playerPaddle.physicsBody?.categoryBitMask = paddleCategory
    computerPaddle.physicsBody?.categoryBitMask = paddleCategory
    self.physicsBody?.categoryBitMask = borderCategory

    let playerScore = SKLabelNode()
    playerScore.fontName = "Pong Score"
    playerScore.text = "0"
    playerScore.fontSize = 100
    playerScore.color = SKColor.white
    playerScore.position = CGPoint(x: -200, y: 220)
    playerScore.zPosition = 3
    addChild(playerScore)

    let comScore = SKLabelNode()
    comScore.fontName = "Pong Score"
    comScore.text = "0"
    comScore.fontSize = 100
    comScore.color = SKColor.white
    comScore.position = CGPoint(x: 200, y: 220)
    comScore.zPosition = 3
    addChild(comScore)

    var comScoreInt: Int = Int(comScore.text!)!
    comScoreInt += 1
    comScore.text = String(comScoreInt)

    var playerScoreInt: Int = Int(playerScore.text!)!
    playerScoreInt += 1
    playerScore.text = String(playerScoreInt)

    let bodyBorder = SKPhysicsBody(edgeLoopFrom: self.frame)
    bodyBorder.friction = 0
    bodyBorder.restitution = 1
    self.physicsBody = bodyBorder
}
}

PS most all of the physics is in GameScene.sks not GameScene.swift, however this is where the bitmasks are.

EDIT:

Ball Config;

Position x:0, y:0, z:0,

Rotation: 0,

Size: w:25, h:25,

Anchor Point: x:0.5, y:0.5,

Color: white,

Blend Factor: 0,

Blend Mode: alpha,

Alpha: 1,

Ik Constraints: min:0, max:360,

Scale: x:1, y:1,

PHYSICS

Body Type: bounding rect,

only dynamic checked,

Friction: 0,

Restitution: 1,

Linuar Damp:0,

Angular damp: 0,

Category, Collision, and Field mask: 4294967295,

Contact Mask: 0

Inital Velocity: dx:100 dy:0

Paddles are the same physics wise PLEASE HELP!

Isaac Dragon
  • 61
  • 1
  • 4
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/151298/discussion-on-question-by-isaac-dragon-restitution-not-working-on-anything-in-sp). – Bhargav Rao Aug 07 '17 at 17:42

1 Answers1

0

Insead of applying an Inital Velocity in GameScene.sks I instead applied a force in GameScene.swift like so: Ball.physicsBody?.applyImpulse(CGVector(dx:50, dy:0)) restitution began working

Isaac Dragon
  • 61
  • 1
  • 4