GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Simulating a Golf Hole

I was just wondering how one might create a semi-realistic hole that a ball can fall into (imagine a top-down view of a golf green). That is, if the ball just grazes the edge of the hole, it will stay on the green but still be shifted a bit as if pulled in by the hole. Any ideas?

Comments

  • owen_dennisowen_dennis Just a guy, you know. Posts: 236Member, PRO
    edited November 2015

    Have the hole change two game attributes when level starts to its own location. So like change hole X to self.position.X and change hole Y to self.position.Y.

    Then make a rule so that when the ball overlaps the hole, it interpolates its self.position.X and self.position.Y to hole X and hole Y in like 0.3 seconds or something. Then I would also interpolate its size to whatever size you want the ball to be when it gets to the bottom of the cup. So like if the ball is 30x30, have it interpolate its width and height to 18x18 or something, probably in like 0.2 seconds so it looks like it hits the bottom and then rolls a little to the center? I don't know, play with it to see what feels right, this is all imaginary anyway.

    Alternately, you could just have there be an animation on the hole so that when a ball touches it, you destroy the ball and then have the hole show an animation of a ball falling into it.

  • mhedgesmhedges Raised on VCS Posts: 634Member
    edited November 2015

    @Rainbros, @owen_dennis ,

    The first method described sounds about what I'd do. I did something very similar for a spinner in an app. If the spinner arrow lands on the line between two values, the arrow is interpolated a bit to the next value at a crawl.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,906Member

    I think the simplest way would be to log the position of the hole. Then make a rule that says if the ball is within a set distance move to the hole x and y

  • RainbrosRainbros Posts: 124Member
    edited November 2015

    Thanks @owen_dennis, @mhedges, and @Lost_Oasis_Games for your answers. But I was really looking for something a bit more complex, I don't have any trouble making a simple hole like you described. I want it to be more realistic, so like imagine a golf putt where the ball is going rather fast and just touches the edge of the hole and is shifted off of it's path without actually going into the hole. Happens all the time in golf but I'm not actually sure what the term for it is. And also if the ball is going too fast, it should go past the hole even if it's heading straight for it, so a simple technique wouldn't suffice.

  • tatiangtatiang Posts: 11,698Member, Sous Chef, PRO, Senior Sous-Chef

    You can check the velocity of the ball and only apply @Lost_Oasis_Games' rule if it's less than a certain value. As for deflections (or whatever they are called), you might just introduce a random direction if the ball collides with the hole at a certain distance from the center of the hole actor (to ensure that it's not going into the hole which would be from 0 to a small number of pixels from the center of the hole actor).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,906Member

    Well as far as goimg over the hole just use the current velocity as a condition of the go in hole rule.
    When self.linear.velocity.x + self.linear.velocity.y < 20

    You can also put actors around the hole that will effect the ball. See some examples of wind effect the code is similar. I believe there is a wind effect video at gshelper's youtube. All the rules for this will end up in your ball actor. It just a matter of setting the conditions.

  • RThurmanRThurman Posts: 2,818Member, Sous Chef, PRO

    Perhaps experimenting with acceleration will help:

  • mhedgesmhedges Raised on VCS Posts: 634Member

    @RThurman , I hadn't seen you around in a while. Welcome back!

  • RThurmanRThurman Posts: 2,818Member, Sous Chef, PRO

    @mhedges said:
    @RThurman , I hadn't seen you around in a while. Welcome back!

    Thanks! Its been a freakishly busy semester. (Three more weeks to go.)

  • RainbrosRainbros Posts: 124Member

    @RThurman Thanks. I'll have to play around with that and see what I can come up with.

  • RThurmanRThurman Posts: 2,818Member, Sous Chef, PRO

    You are welcome. Hope it works out for you.

Sign In or Register to comment.