How do I limit a "throw" object to one instance until picked back up?

0 favourites
  • 7 posts
From the Asset Store
Throw daggers and hit the most fruit! Watch out for the wind, if you run out of daggers you'll lose the game!
  • I'm working on a throwable object (a basketball) that needs to be charged to throw. I've got it working pretty well with the bullet behavior and a timer. The problem is I can spawn multiple balls at will after charging and would like to limit it to one at a time until the ball is picked back up. I have been unsuccessful with setting instance variables restricting a second charge before the first ball is picked up but I just break it every time.

    I am also trying to figure out a way to get the ball to slow down and stop bouncing over time so it's not continuously bouncing all over the place but I've been unsuccessful with that also. Hope someone can provide some insight, as always it's greatly appreciated :) I have uploaded a screencap of the events.

    i.imgur.com/Frc6xzR_d.jpg

  • Try changing your code like this:

    .

    To slow down the ball after each bounce you can add this event:

    Ball on collision with Floor -> Ball set speed to (Self.Bullet.Speed/2)

  • Awesome, I changed it like you said and also added a condition for "true" to "on pressed" and that seems to have worked :) As for the slowdown, I used the /2 on collision with ground and it does slowdown but when it reaches the end of deceleration it starts glitching really fast in place. It also doesn't actually stop on the ground. It's slightly levitating while twitching. I'm not sure if that's because it's still trying to bounce even though the speed is 0?

  • You can stop the bullet completely after several bounces, or when the speed is quite low (<10 for example).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Also, I just realized if T is tapped but not held during the full duration of the timer, it locks the ball from ever being spawned because it sets the value to "false" but it did not work using "is down" either.

    Also it's getting really annoying waiting for moderator approval on every reply I post

  • Also, I just realized if T is tapped but not held during the full duration of the timer, it locks the ball from ever being spawned because it sets the value to "false" but it did not work using "is down" either.

    This shouldn't happen with the code you posted earlier, because the timer is stopped every time T is released.

    Also, it may be easier to do this charging thing without the timer and Basketball variable. Add a variable chargeKeyPressed, change your code to this:

    On T pressed : set chargeKeyPressed=time
    
    On T released 
     chargeKeyPressed<(time-1) : Spawn ball
    

    .

    Also it's getting really annoying waiting for moderator approval on every reply I post

    This happened to me once. Maybe the more comments you post, the less often they need approval?

  • I ditched the timer and used a variable and set add 1 to variable every 0.25 seconds that the button is held down so that seems to have fixed the issue. It doesn't respawn until it's picked back up or after a cooldown if it's destroyed (outside layout) and releasing the button too early simple resets the variable to 0. I also used the less than speed condition to stop the ball like you suggested and also added a platform behavior on stopped so it drops to the ground and doesn't stay hovering. That seems to have stopped the glitching so it's all working now.

    And yea I'm not sure why everything I posted was being flagged. It started when the forum switched to C3. Maybe it's because I'm on mobile.

    Anyway, thanks again for the help :)

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