How do I Science the Sh!7 out of a non Physics Object?

0 favourites
  • 14 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I am currently working on an infinite scroller game (similar to Yeti Hits Penguin), except I could not really use Physics since I set my object's X to the center screen. Instead I am using the Custom Movement behavior. It works quite well and I like it, except I want to add more dynamics to the game and want the object to bounce & spin realistically as it hits the ground. Thus I added the Rotate behavior to mimic real world spin.

    However, I am still not sure how to work out the maths(or physics) needed to transfer/carry out the Current spin(rotate.speed) + vertical(dx) + horizontal(dy) values into New spin(rotate.speed) + new vertical(dx) + new horizontal(dx) values. Can anyone pitch in with some realistic maths/physics formula? What about friction perhaps? I am totally lost for words at this as I suck at numbers. Fortunately enough, angle is pretty much covered by CM (-ball.CustomMovement.MovingAngle). Thanks!

    bloodshot

  • The simplest way would be to use the physics behavior and just move the player instead of the terrain. Or you could use the chipmunk physics plugin instead since it works fine if you move an object. The normal physics behavior throws the object when you move it which is why you can't use it to begin with I guess?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It 'hits the ground', so i suppose in is not endless. The 'hitman' stays on position. Use the physics/chipmunk and follow the 'object' with the camera.

    /tutorials/626/making-a-smooth-following-camera

  • Thanks guys!

    I guess chipmunk is the best way to go around it. At the moment, I am just quite intrigued at replicating this type of movement using c2's native event.

    Found this for example:

    jsfiddle.net/gfcarv/r2rS6

  • You can do that in five events. The first does the motion, and the other four are for bouncing off each wall.

    global number radius=16

    global number gravity=1000

    global number elasticity=0.5

    every tick

    --- add gravity*dt to vy

    --- set x to self.x+vx*dt

    --- set y to self.y+vy*dt

    y>640-radius

    --- set y to 640-radius

    --- set vy to -elasticity*abs(vy)

    y<radius

    --- set y to radius

    --- set vy to elasticity*abs(vy)

    x>480-radius

    --- set x to 480-radius

    --- set vx to -elasticity*abs(vx)

    x<radius

    --- set x to radius

    --- set vx to elasticity*abs(vx)

  • I think this would make a nice 2d realistic pong engine that eliminates the use of physics. I imagine it would perform nicely on mobile due to it's full controllability.

    Did some digging into rotation as well, if anyone else is interested. Though I'm still not sure how to put the pieces together.

    gamedev.stackexchange,com/questions/2472

    R0J0hound Thanks for translating it into c2 language!

  • Could R0J0hound or anyone please tell me how or why this ball won't stop moving after introducing a spin/horizontal speed? Thanks!

    dropbox.com/s/jfj6zjzbp7oua ... .capx?dl=0

    EDIT: Also found a formula at

    physics.stackexchange..com/questions/11686/finding-angular-velocity-and-regular-velocity-when-bouncing-off-a-surface-with-f

    But not sure how to translate it to c2.

  • It doesn't work because the article you used made typos when writing the equations. Look at the paper it references for the correct formula. Also there's no need to use the custom movement behavior, it adds nothing but making the equations longer.

    https://dl.dropboxusercontent.com/u/542 ... e_rot.capx

  • Looks great! Thank you R0J0hound! Actually, the reason why I added custom movement + rotation was so that i could control the ball later on to go left, right or up(to bounce), since they would give me access to velocity(x,y)+rotation.speed. (thinking about a realistic rolling and bouncing ball-mario type game) I just can't stop thinking about different game ideas now. lol This is powerful! Cheers

    PS.

    Any ideas how to plug this formula into the football object? I reckon the radius/diameter(new word for me ) would be different each angle and each time it touches the ground. Thanks again!

    Best,

    Bloodshot

  • You can control the speed by changing the vx,vy, and w variables directly, but I guess that's enough about that.

    That formula only works for balls, and even that last link you posted will only work for balls.

    You could go for something more general purpose like this:

    r0j0-s-experiments_p955579?#p955579

    And the tutorial it was based on:

    http://allenchou.net/game-physics-series/

    You could also read here for info on how the box2d or chipmunk libraries work and use that.

    http://myselph.de/gamePhysics/index.html

    There's also this classic reference, but I guess it doesn't take into account friction:

    http://chrishecker.com/Rigid_body_dynamics

    In summery you either need to follow one of those, derive your own, or use a preexisting solution such as box2d or chipmunk. The first two will require you to ramp up your math skills.

    Edit:

    this link is also helpful:

    http://www.myphysicslab.com/collision.html

    edit2:

    It seems to have the math derived here:

    https://en.wikipedia.org/wiki/Collision_response

  • Goodies! Bookmarking them now. Thank you so much! b(^ 0 ^)d

    EDIT: Interesting rugby ball bouncing simulation.

    https://arundquist.wordpress..com/2015/07/06/rugby-ball-bouncing/

  • Ok, here's the general purpose case with any ellipse bouncing on the floor with friction.

    https://dl.dropboxusercontent.com/u/542 ... tion2.capx

    Any other shape can work too, it just requires mass, inertia, and contact point calculations.

  • Sweet! Now trying to understand how it works. Thanks!

    R0J0hound

    Played around with the capx a little bit.. I added a ground sprite with the condition if ball.Y > ground.Y-ry. But I think this is not the way to go if I want the ball to bounce off other object/obstacle/instance as well. Any tip/advice on how to make it bounce/interact with other instances or sprite objects using this method? Thanks! - bloodshot

  • Hmm, I seemed to have missed your last reply.

    The math is the capx is simplified for just horizontal ground. The first step would be to make it work with any angle. Actually you can do this by taking the velocity and using a dot product with the angle of the surface to get perpendicular and parallel velocities that can be plugged into the equations already there. That covers getting the bounce math to work.

    Next the collision detection and resolution would need an overhaul. This is what keeps the football from falling through the floor at low speeds and lets us know when to bounce. It is also what gives us the point of collision. Right now we have oval vs horizontal line working. New would be oval vs any line. The math there isn't too pretty which explains why ovals aren't usually a common shape in physics libraries. Also you'll need to work out the formulas. Either that or use the iterative approach.

    Ok, next we need oval vs oval collision detection. The simplest solution is to convert the oval to a polygon first. Then you'd take the two ovals and see if they overlap. If they do we need to separate them till they collide at only one point. The two ways to do this is to either move backward in time to they just touch, or use something like SAT or GJK/EPA to move them apart.

    That just covers the simple case of only one moving oval and everything else is static. For collisions between two moving objects the bounce math now needs to use the relative velocity (Va-Vb) between the two objects instead of just the velocity of one. Otherwise the stuff above is more or less the same.

    One caveat is when there are multiple objects that need to be pushed out of each other, then correcting one pair can push them into other objects. This is usually solved by repeating this check multiple times to reduce the amount of objects overlapping. You'll also want to make collisions faster by checking if the object's bounding box is overlapping first, before the other more costly oval-oval collision check.

    In summery you will be creating a full blown physics engine. I have roughly outlined one approach, but there are many tweaks that improve speed and accuracy.

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