GameSalad

Howdy, Stranger!

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

Actor Bouncing across screen

So I've got this endless runner. My hero flying around trying collect points from things that are spawned just off screen on the right side and scroll across to the left. I've also got a couple of other things like foreground and background objects also doing the same thing. This all works - which is great. I now had the idea (of course, just to make it more difficult) of having an actor be spawned from the right just like all of the rest - except arc to the 'ground' and bounce off screen (left). - just like a ball would do. I looked around and found this discussion: http://forums.gamesalad.com/discussion/74615/keep-object-from-moving-on-y-axis-random-y-position

Someone came up with a solution which worked for the poster, but not for me. Here's what he said to do:

@Rabid Parrot said:
Create a real attribute within the building actor. Call it "MyY".

Add the following statement to the building actor.

Change attribute self.MyY to self.posY

Make another rule,

If self.posY < self.MyY
constrain attribute self.posY to self.MyY

What I've also done is enter a value (3) into the Y coordinate of Gravity in the scene attribute and applied the above. My actors still slide off screen - downward.

Comments

  • SocksSocks London, UK.Posts: 12,822Member
  • SocksSocks London, UK.Posts: 12,822Member
    edited August 2015

    Example attached . . .

  • Village IdiotVillage Idiot Posts: 486Member, PRO

    Thanks @Socks That looks like it should work within my game – and surprisingly simple. I noticed that you didn't enter any values for gravity in the scene attribute. I thought that if something were to behave as if there was gravity you had to enter a value in there.

  • SocksSocks London, UK.Posts: 12,822Member

    @monkeyboy simian said:
    Thanks Socks That looks like it should work within my game – and surprisingly simple. I noticed that you didn't enter any values for gravity in the scene attribute. I thought that if something were to behave as if there was gravity you had to enter a value in there.

    If I were you I would avoid scene gravity, most people just apply a downwards acceleration to the object they want to be effected by gravity, this gives you much more control.

  • Village IdiotVillage Idiot Posts: 486Member, PRO
    edited August 2015

    @Socks I'll take your advice - it made a mess of my game. I'm puzzled though. Your ball actor shoots out at 270 (which as I understand it, is left), the ball then slowly falls to the ground and bounces. I can understand that the bounce comes from the physics of the actor. But why is it falling?

  • ArmellineArmelline Posts: 4,718Member, PRO

    270 is down. There are only three things happening in @Socks' demo:

    1. The actor is moving at a default speed of 500, to the left (set using the motion.linear velocity.x attribute, which @Socks set to -500). This is what causes the ball to move to the left.
    2. The actor in constantly fighting against any upwards motion, because it is being told to accelerate downwards (270). This is what gives the illusion of gravity, and causes the ball to fall down.
    3. The actor collides with the floor. This is what stops it disappearing off the bottom of the screen, and is also what propels the ball upwards when it touches the floor.
  • SocksSocks London, UK.Posts: 12,822Member
    edited August 2015

    @monkeyboy simian said:
    I'm puzzled though. Your ball actor shoots out at 270 (which as I understand it, is left) . .

    Like Armelline says 270° is down, in maths 0° is at the 3 o'clock position and angles increase as you move counterclockwise.

  • Village IdiotVillage Idiot Posts: 486Member, PRO

    @Socks @Armelline ..ohhhhh.. I get it. Sorry, I'm not very cluey at all – especially with maths. I think I really should have known what 270 meant though. In school (which was a-hem, some time ago now), I was the kid scribbling all over his folder during maths. Regrets. I've got it working – just started tweaking the amount of bounce etc. Thanks again, again – both of you.

  • ArmellineArmelline Posts: 4,718Member, PRO

    @monkeyboy simian said:
    Socks Armelline ..ohhhhh.. I get it. Sorry, I'm not very cluey at all – especially with maths. I think I really should have known what 270 meant though. In school (which was a-hem, some time ago now), I was the kid scribbling all over his folder during maths. Regrets. I've got it working – just started tweaking the amount of bounce etc. Thanks again, again – both of you.

    Socks has a way of making things so simple they're confusing (which is a good thing!). I'll admit I opened his project and spent a good minute going "How the fudge is he making the balls move left?" before it occurred to me he might have set a default linear.velocity.x value.

Sign In or Register to comment.