(Fixed) What's wrong with my maths?

0 favourites
  • 13 posts
From the Asset Store
Be quick and choose whether the shown equation is right or wrong.
  • At the start of the frame, I try to position those decorative bushes randomly to the ground, but sometimes they appear higher.

    The code is basically this:

    Start of frame: 
    set x to ground.x + cos(ground.angle)*random(ground.width)
    set y to ground.y + sin(ground.angle)*random(ground.width)
    [/code:2d1dakb5]
    
    [u][b]This is now fixed. I was wrongfully setting both X and Y with different random numbers,[/b][/u]
    
    [u][b][url=https://rawgit.com/neverk/BouncyBoi/master/game/index.html]Can be tested here[/url][/b][/u]
    
    [img="https://raw.githubusercontent.com/neverk/BouncyBoi/1bb62198/wrong-pos.jpg"]
  • Nothing is wrong with your equation, there is something else at play here.

    Have you tried putting them on the same layer first before setting the position? Perhaps some parallax is the issue.

  • To add to R0J0hound's suggestion, perhaps Pinning them with offset will be more straightforward to control?

  • Nothing is wrong with your equation, there is something else at play here.

    Have you tried putting them on the same layer first before setting the position? Perhaps some parallax is the issue.

    The decoration is in the same container with the ground.

    I have two layers for the level and they both have the same parallax rate. I disabled the "move to layer "levelbg"", but it didn't fix the problem.

    faulknermano

    Good suggestion, but it won't help now, because the cap appears randomly.

  • Check your imagepoint origins maybe? If you have variations on different animation frames the origin point may not be the same on each frame.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Check your imagepoint origins maybe? If you have variations on different animation frames the origin point may not be the same on each frame.

    Thanks for the suggestion. I checked the decoration, but it has only one frame at the moment. I'm intending to add more frames, but after it works... The ground is tiled background and the origin is set to top left.

  • Do you move the ground sprites at all?

    Does it still occur if you use “time =0.1” instead of start of layout?

    Worst case, make a copy of your project and start removing everything else until it stops occurring. At the very least it will give a minimal example.

    To me it looks like things are being moved after you set the position.

  • Do you move the ground sprites at all?

    Does it still occur if you use “time =0.1” instead of start of layout?

    Worst case, make a copy of your project and start removing everything else until it stops occurring. At the very least it will give a minimal example.

    To me it looks like things are being moved after you set the position.

    Well, the ground is very static and I'm not moving it at all, at least not on purpose...

    I have two "on start of layout" events. I have to check if that is the case. --> EDIT --> didn't help.

    R0J0hound Still occurs, even I set: time = 0.1

  • This happens if I set the pos every 0.2 secs

  • 3 suggestions:

    1. you probably already checked, but the offset has to be the left bottom or top of the ground object, not the middle

    Update - I just saw the video - this is not the problem, because the bush would be placed wrong bit still move together with the ground. also I ready you checked this already

    2. For a different solution, you can add a few image points and select one at random to place the other object

    3. check if your bush is on the same layer as the ground. If it is on a different layer, the x-y coordinates could be different.

    update - just ready you checked this already

  • Rounding error?

    Maybe try setting the position with move at angle instead.

  • 3 suggestions:

    1. you probably already checked, but the offset has to be the left bottom of the ground object, not the middle

    Update - I just saw the video - this is not the problem, because the bush would be placed wring bit still move together with the ground

    2. For a different solution, you can add a few image points and select one at random to place the other object

    3. check if your bush is on the same layer as the ground. If it is on a different layer, the x-y coordinates could be different.

    1. Yes, the origin is at bottom-left.

    2. That's not probably a solution, because I would like to have a dynamic positioning, because the ground can be any width...

    3. I tried with a same and different layer, and the problem remained...

    oosyrag That "move at angle" might work, but still, I would like to figure out what's wrong with this one...

  • I got it working. The problem was that I was setting both x and y with different random numbers.

    I fix it by using a local variable instead of generating a random number in the equation...

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