One way street

This topic contains 3 replies, has 2 voices, and was last updated by  Ken Walker 4 months, 2 weeks ago.

  • May 4, 2016 at 2:55 pm #148983

    I’m trying to wrap my head around the best way to create a one way street on a table. What I need is a means to keep the ball from traveling in the incorrect direction. The ball can go off of the street at any point, but when it tries to roll on the street it should be able to only enter at an intersection and then travel in only one direction. Can you point me in a good direction?

    Thanks,

    Ken

  • May 4, 2016 at 3:20 pm #148984

    You could have it roll over a spot that activate a gravity field or one of the other fields so the ball is pulled upward. Just do a temporary effect for like 1 or 2 seconds.

  • May 5, 2016 at 3:38 pm #149119

    http://kennydwalker.net/onewaydiagram.png

    I’m still trying to get the one way street thing going. Referring to the diagram link above.

    The green rectangle is set up as “Light”

    The red circle is set up as a “TableObject” bumper, but it’s parent node is set to the Light node above.

    If approaching from the top of the diagram, I’m trying to have contact with the Light object, disable the TableObject.

    I’m able to get at this specific Light object using a naming pattern. When a collision with that Light object is detected I used sequence to set the “collidesWithMainBall” property to false, then call the disallowBallCollison method on the child object, wait for a couple of seconds, then set the “collidesWithMainBall” to true and call allowBallCollision on the child object.

    To me this seems like it should “disable” the bumper long enough for the ball to pass over it’s space and continue going.

    Obviously if approaching the street fro the bottom of the diagram it will collide with the bumper in a normal fashion.

    Am I missing something obvious?

    Thanks.

    Ken

  • May 10, 2016 at 9:46 am #149634

    Finally got this working.

    I created a function in GameScene_Operations.swift as below and called it when the ball collides with my custom “light”. Works just like I want. I’m using ½ second delay.

    //kdw
        func turnOffOneWayBumpersFor(time:NSTimeInterval){
            
            self.enumerateChildNodesWithName("//*") {
                node, stop in
                
                if (node.name == "Bumper") {
                    
                    
                    if let someField:SKSpriteNode = node as? SKSpriteNode {
                        let oldCategoryBitMask = someField.physicsBody?.categoryBitMask
                        someField.physicsBody?.categoryBitMask = 0
                        
                        let oldContactBitMask = someField.physicsBody?.contactTestBitMask
                        someField.physicsBody?.contactTestBitMask = 0
                        
                        let wait:SKAction = SKAction.waitForDuration(time)
                        let run:SKAction = SKAction.runBlock{
                            
                            someField.physicsBody?.categoryBitMask = oldCategoryBitMask!
                            someField.physicsBody?.contactTestBitMask = oldContactBitMask!
                        }
                        self.runAction(SKAction.sequence([wait, run ]))
                        
                        
                    }
                    
                }
                
            }
            
        }

You must be logged in to reply to this topic.