Fix My Physics?

Post your own tutorials, guides and demos.

Post » Sun Nov 30, 2008 9:22 pm

Hey, I've had this stuck for a few months and have not been able to figure out collisions.

It's a top-down 360 spaceship movement with a loose-drifting movement and I need the ship to bounce correctly.

I have 8 Variables for the ship.

Mass
MovSpeed = How much push the engines are giving
XPos = X Position
YPos = Y Position
XMov = The movement from the engines along the X plane
YMov = The movement from the engines along the Y plane
XMovEx = The movement from external forces along the X plane
YMovEx = The movement from external forces along the Y plane

I needs to make the ship bounce when it collides with another object. But not some arrbitrary amount. If a heavy & slow object pushes against the ship then the ship gets moved out of the way (Like a bulldozer) or if a extremely fast yet small object hits then the appropriate force would be applied to the ship.

If anyone can help me on this that'd be just outstanding!

I hope I made some sense.
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Sun Nov 30, 2008 9:29 pm

Replace the collision event with

+ On collision between Ship and Red Square
-> Ship: set XMov to Ship('XMov') * -1
-> Ship: set YMov to Ship('YMov') * -1

I think that's what you want :P

Use -0.5 instead of -1 and you'll bounce back with half the velocity you hit it, and so on. Hopefully you can probably work it out from there.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,574

Post » Mon Dec 01, 2008 10:27 am

Any reason why you dont just use the built in physics engine ? It saves you a lot of time in the long run i find
B
4
S
2
G
5
Posts: 641
Reputation: 3,011

Post » Thu Dec 11, 2008 9:01 am

[quote="Ashley":32takzi2]
+ On collision between Ship and Red Square
-> Ship: set XMov to Ship('XMov') * -1
-> Ship: set YMov to Ship('YMov') * -1
[/quote:32takzi2]

The only problem with that, while it's the closest thing I can code for a custom engine bounce, it doesn't actually allow for realistic rebounds, it will ALWAYS rebound in the exact opposite direction at which you came at the obstacle.
It's good enough for some things, but I would REALLY love a way to code in real bounces similar to the bounce object :D

I want to put time manipulation stuff in my game, and either this bounce thing getting solved or scaling physics values to pixels per second will make what i need to do possible :D
Just to clarify, say in my super speed demo i posted ages ago, you slow down time say, a thousand times slower, that would mean you have to make the player object move 1000 times faster to make it look as though the player's speed isn't affected. In a custom engine I can do this no sweat, but the player doesn't bounce properly, but if i'm using the physics object, the player bounces perfectly fine, but when i use the code to make the player speed up the same ratio that time has slowed down, he doesn't go the right speed at all :(
it's like:
Custom engine: speed = 200, times that by 1000, new speed would be 200000 pixels per second
Physics engine: speed = 200, times by 1000, physics value still listed as 200000 but travels at what appears to be a lot slower than what it should be. The value of the velocity has no doubt been multiplied by 1000, but it's like the velocity in physics uses a different ratio or something. Almost as if 400 velocity is NOT twice as fast as 200, if you get my drift. Correct me if i'm wrong
sorry bout the wall
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Thu Dec 11, 2008 12:39 pm

In my universe demo, I made custom physics with bouncing. It isn't entirely realistic, but it's close enough. All it needs is the normal angle of the surface against whom the bounce happens. With spherical planets like in that demo, calculating the normal angle is easy, but if the object is irrelugar, calculating normal angle is very difficult. With cubes, it is very easy, though. Interested?
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Thu Dec 11, 2008 12:45 pm

Actually that's quite interesting, sparking off all manner of ideas in my mind as we speak.
Although I'm hoping i don't have to have detectors everywhere.
I have the code to find the correct bounce angle but finding the normal of the colliding wall was always the problem.
One time I set up a complex loop that shot out detectors that stopped on overlapping solids then returned the average angle of a certain area infront of the player's direction of motion... but it didn't work out so well...

I'm thinking now, I could probably use squares and circles to find the normal thingy, and to find which side of the square the player hits i could probably use an angle between points thing.... hmmmmm

Is that what you did?
B
3
S
2
G
5
Posts: 351
Reputation: 2,377


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 1 guest