1

Excuse the naming conventions and the way I indent and create new spaces in my code I know it's not normal but i'm weird D:

Anyway I set my restitution to 1 and it didn't seem to work so I even tried 1.0 to see if I had to do it that way and it didn't work. By it i'm referring to object(s) bouncing off the borders/frame.

I can't do CGVectorMake either since the swift i'm using doesn't allow it. Anyone have any helpful tips?

Only idea I had was to change gravity of the frame itself but everything I try doesn't work. Thanks!

//
//  GameScene.swift
//  Pong
//
//  Created by Mac2 on 1/16/17.
//  Copyright © 2017 Mac2. All rights reserved.
//

import SpriteKit
import GameplayKit

class GameScene: SKScene
{
     var trump = SKSpriteNode()
     var player = SKSpriteNode()
     var opponent = SKSpriteNode()

override func didMove(to view: SKView)
{
    //essentially link them to the physical nodes we created in the gamescene
    trump = self.childNode(withName: "trump") as! SKSpriteNode
    player = self.childNode(withName: "player") as! SKSpriteNode
    opponent = self.childNode(withName: "opponent") as! SKSpriteNode

    //to initialize the game we need the ball to be going somewhere so we make it go on an angle to the player (not opponent)

    trump.physicsBody?.applyImpulse(CGVector(dx: -20, dy: -20))

    let border = SKPhysicsBody(edgeLoopFrom: self.frame)
    //create variable representing the frame or border of the gamescene

    border.friction = 0 //we don't want friction to the borders
    border.restitution = 1.0 //we want bouncyness to the borders

    self.physicsBody = border //wrap it all up and save it as the physics representation of the gamescene frame
}

override func update(_ currentTime: TimeInterval)
{
    // Called before each frame is rendered
}
}
Chandan Rai
  • 9,879
  • 2
  • 20
  • 28
Kenny Kiriga
  • 39
  • 1
  • 5
  • Does anyone have any idea? Can't seem to literally do anything. I've tried everything I could find on google :( – Kenny Kiriga Jan 17 '17 at 14:46
  • okay so in the gamescene I edited the ball's gravity to being able to be affected by gravity and now frame restitution works...? What? Anyone know why this is the case? – Kenny Kiriga Jan 17 '17 at 15:41
  • So update I'm changing linear damping by the smallest unit I can (in the negatives) and it then allows restitution effect to work. But the downside to that is that the movement of the node will then start increasing dramatically after about 5-10 seconds :( – Kenny Kiriga Jan 17 '17 at 20:14
  • I figured it out! I literally just had to change the impulse to 50, 50 I'm sure I can do something like 40,40 but I know 30,30 is too dang slow so. Found the solution – Kenny Kiriga Jan 17 '17 at 20:31

0 Answers0