How to set random directions on a falling object

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • in this picture it shows my code, i want the cookie to spawn at the cursor(which it does)but the set its direction either left or right randomly, i tried using random but it didnt work, so i resorted to global variables. The problem is that it will always go to the right, never to the left,

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Random(a, b) generates a random float between a and b, including a but not including b.

    You have to use choose:

    Choose one of the given parameters at random. E.g. choose(1, 3, 9, 20) randomly picks one of the four numbers and returns that.

  • Hi,

    Your code is a bit... Messy 0_0

    And that is the reason your code is not working.

    You should rework your logic.

    Add a "Tween Behavior" and "Physics" to your cookie.

    On Left button clicked
     -> Create Object Cookie at cursor.X, cursor.Y
     Tween(one propriety) property X Scale, End Value: 2, time: 2, loop: yes, ping pong: yes
     Tween(one propriety) property Y Scale, End Value: 2, time: 2, loop: yes, ping pong: yes
     Physics Apply force at angle Force: (set it based on your sprite), angle: random(0,360) or choose(any angle, any angle)
    

    and this replace all of your logic with wait and size.

    Also a good thing would be to check examples, there is a lot of good ideas.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)