How do I get my actions to default to the intended input?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • I'm trying to make a system where the player can pick up blocks, then throw them left, right, up, or down. What's happening right now is the first time the player lets go of a block, it gets thrown to the right, regardless of what direction the player is facing/aiming. The second time the player lets go of the block, it seems to work as intended.

    Can anyone tell me why the first throw is always to the right, but subsequent throws can be aimed as intended?

    Here's a screenshot of the events in question:

    And here's a playable example:

    construct.net/en/free-online-games/block-example-87657/play

    Note that I only have gamepad controls for picking up/throwing at the moment. I'll try to incorporate the keyboard in the future.

  • Try setting bullet speed before setting the angle of motion.

    In fact, you should move these three actions into the parent event on your screenshot:

    Block set bullet speed
    Block set gravity
    Block set bounce off solids
    

    Then:

    ...If player mirrored: Block set angle of motion to 150
    ...Else: Block set angle of motion to 30
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Setting the speed before the angle of motion like dop suggested probably will fix it.

    Why that fixes it is because when the speed is 0 trying to set the angle of motion will do nothing. That’s because the bullet behavior stores its velocity as horizontal and vertical components instead of an angle and direction. As such when speed is zero the angle of motion will always be 0. In the simple case without gravity this is all the behavior is doing if you want to try the math and get an intuition of why.

    Function setAngleOfMotion(ang)
    — set speed to distance0,0,vx,vy)
    — set vx to speed*cos(ang)
    — set vy to speed*sin(ang)
    
    Function setSpeed(speed)
    — set ang to angle(0,0,vx,vy)
    — set vx to speed*cos(ang)
    — set vy to speed*sin(ang)
    
    Every tick
    — set x to x+vx*dt
    — set y to y+vy*dt

    Anyways, all you need to know is set speed first then angle and you’ll be golden.

  • Thank you both! Works perfectly, and now I understand why!

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