How do I modify this code to drop a ball from mid-air?

0 favourites
  • 3 posts
From the Asset Store
320 high-quality cinematic sound effects for trailers and game scenes.
  • A few years back, R0J0hound, you saved the day with some code that launched a 2D baseball into 3D space.

    Would you (or anyone else) know if it's possible to use this code to drop a ball onto its shadow from above?

    Specifically, I'm reusing this code for characters in a Beat 'em Up. It works great for jumping and knockback, but when they respawn, I'd like to start the sprite 100px above the shadow, and have them drop straight down to the floor.

    Is it possible to change the variables in this formula? Or is it something different entirely (i.e. should I just use MoveTo)

    Thank you again and as always!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So basically you’d just need to set the z when you create it much like the velocities. For example here it starts with a z of -150. Then you can make it stop on the ground by comparing the z with 0.

    every 1 second
    — create shadow at random(640), random(480)
    — create ball at shadow.x, shadow.y-150
    — set z to -150
    
    Every tick
    — set y to self.y-self.z
    — set position to self.x+self.vx*dt, self.y+self.vy*dt
    — add 200*dt to vz
    — add vz*dt to z
    
    Z>0
    — set z to 0
    — set vz to -0.5*abs(self.vz)
    
    Every tick 
    — set y to self.y+self.z
  • Amazing, thank you! I really appreciate it—I'll try it out tonight! Thanks!

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