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

Get help using Construct 2

Post » Fri Mar 18, 2016 10:23 am

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
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

Post » Fri Mar 18, 2016 5:36 pm

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?
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Fri Mar 18, 2016 8:00 pm

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
B
33
S
18
G
27
Posts: 2,447
Reputation: 20,358

Post » Fri Mar 18, 2016 9:48 pm

Message: bloodshot can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
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:
http://jsfiddle.net/gfcarv/r2rS6/
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

Post » Sat Mar 19, 2016 5:21 pm

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)
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Sat Mar 19, 2016 6:07 pm

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! :)
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

Post » Mon Mar 21, 2016 2:40 pm

Message: bloodshot can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Could @R0J0hound or anyone please tell me how or why this ball won't stop moving after introducing a spin/horizontal speed? Thanks!
https://www.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.
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

Post » Mon Mar 21, 2016 5:58 pm

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
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Mon Mar 21, 2016 6:32 pm

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! :D 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
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

Post » Mon Mar 21, 2016 9:06 pm

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
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests