I intend to make a simple flash game where you're basically a ball rolling down a hill, and obstacles would appear and have to be dodged as you progress. The ball would not actually be moving, it would be in the center of the screen, and so the hill would have to work as a conveyor belt in a sense, with obstacles randomly appearing on the hill.
I know this is a vague question, but I can't really think of how I would implement this. How I would make the hill appear as the though it were moving and then when an obstacle is put on, how it would move with the hill to create the illusion of the ball moving consistently.
I'm just trying to think of how the mechanic would work, so any advice would be helpful.
Thanks
The mechanics are called parallax scrolling.
Parallax scrolling is a special scrolling technique in computer graphics, wherein background images move by the camera slower than foreground images, creating an illusion of depth in a 2D video game and adding to the immersion. The technique grew out of the multiplane camera technique used in traditional animation since the 1940s.
Now, this describes a side scroller game. You use the same principles in a forward movement game. Objects further away from you move towards you more slowly than objects closer to you. Your focus is the horizon in a forward movement game.
You might get a better answer on the Game Development exchange site.
Related
I want to track a ping pong ball during game using opencv.
I'm not really sure how to tackle this problem. I tried using the orange color for detecting the ball each frame, via cv.inRange in RGB & HSV color space, however this did not work quite well. But could any kind of preprocessing help with that?
Also using MOG the ball can be seen quite well when moving (still a lot of noise due to moving people in the scene), was not the best way I guess.
Any tips how to achieve a ball tracking script?
Here is an image how the scene looks like in a "bad" frame (ball is in the middle above the net):
I'm happy to get any tips,
thanks in advance
One possibility is to just ask people not to walk behind the table, to try to improve the performance of background subtraction/MOG. You can then crop out the players, to focus only on the table area.
There are also algorithms to detect people - e.g. HOG-based methods. https://thedatafrog.com/en/articles/human-detection-video/ includes a tutorial.
You could also try blob detection after subtracting the background, and filtering out any blobs that are too large, since you know how big the ping-pong ball is.
Another concept is to keep track of where you think the ball should be based on previous measurements.
Let's say I have a SKSpriteNode that represents a car wheel, with a circular SKPhysicsBody successfully attached to it. The genre would be sideways scrolling 2d car driving game/simulator, obviously.
What I want is to calculate all the in-motor physics myself without resorting to the SpriteKit physics engine quite yet. I'd like to keep full control on how the mechanics of the motor, clutch, transmission etc. are calculated, all the way to the RPM of the drive wheel.
From that point onwards, though, I'd happily give control to the SpriteKit physics engine, that would then calculate what happens, when the revolving drive wheel touces the surface of the road. The car advances, slows down, accelerates and/or the wheels slip, whatever the case might be.
Calculating the mechanics to get the wheel RPM is no problem. I'm just not sure on how to go on from there.
I'm able to rotate the wheel simply by applying zRotation in the update: method, like this:
self.rearWheelInstance.zRotation += (self.theCar.wheelRPS/6.283 * timeSinceLastUpdate); // revolutions / 2pi = radians
This way I'm able to apply the exact RPM I've calculated earlier. The obvious downside is, SpriteKit's physics engine is totally oblivious about this rotation. For all that it knows, the wheel teleports from one phase to the next, so it doesn't create friction with the road surface or any other interaction with other SpriteKit physicsBodies, for that matter.
On the other hand, I can apply torque to the wheel:
[self.rearWheelInstance.physicsBody applyTorque: someTorque];
or angular impulse:
[self.rearWheelInstance.physicsBody applyAngularImpulse: someAngularImpulse];
This does revolve the wheel in a fashion that SpriteKit physics engine understands, thus making it interact with its surroundings correctly.
But unless I'm missing something obvious, this considers the wheel as a 'free rolling object' independent of crankshaft, transmission or drive axel RPM. In reality, though, the wheel doesn't have the 'choice' to roll at any other RPM than what is transmitted through the drivetrain to the axel (unless the transmission is on neutral, the clutch pedal is down or the clutch is slipping, but those are whole another stories).
So:
1) Am I able to somehow manipulate zRotation in a way that the SpriteKit physics engine 'understands' as revolving movement?
or
2) Do I have a clear flaw in my logic that indicates that this isn't what I'm supposed to be trying in the first place? If so, could you be so kind as to point me to the flaw(s) so that I could adopt a better practice instead?
Simple answer, mixing 2d UI settings, like position and zRotation, with a dynamic physics system isn't going to have the results you want, as you noticed. As you state, you'll need to use the pieces of the physics simulation, like impulse and angular momentum.
The two pieces of the puzzle that may also help you are:
Physics Joints - these can do things like connect a wheel to an axel so that it can freely rotate, set limits on rotation, but still impart rotational forces on it.
Dynamically Adjusting Physics Properties - like increasing friction, angular dampening or adding negative acceleration to the axel as the user presses the brakes.
After quite a few dead ends I noticed there is in fact a way to directly manipulate the rotation of the wheel (as opposed to applying torque or impact) in a way that affects the physics engine accordingly.
The trick is to manipulate the angularVelocity property of the physicsBody of the wheel, like so:
self.rearWheelInstance.physicsBody.angularVelocity = -self.theCar.wheelRadPS;
// Wheel's angular velocity, radians per second
// *-1 just to flip ccw rotation to cw rotation
This way I'm in direct control of the drive wheels' revolving speed without losing their ability to interact with other bodies in the SpriteKit physics simulation. This helped me over this particular obstacle, I hope it helps someone else, too.
How do you simulate sliding, image a circle on screen and its sliding across the screen background. Or a puck sliding in an air hockey game.
This app shows exactly what I want if you care to see an example in action!
https://itunes.apple.com/gb/app/puck-puck/id463455207?mt=8
The app is free and put it there in case someone wanted to download it to exactly see what I was talking about. My current method is using physics.start() and setLinearVelocity(200, -300), then when the object is returning "falling" down screen i physics.pause() this gives appearance of fast - gradual stop. Wondering if another way so I could use friction to change things up.
Sliding friction is a force with a constant magnitude and a direction opposite to the direction of motion.
The magnitude is a free variable you can adjust to get the motion you like. In real life it's proportional to the normal force (the force perpendicular to the surface, related to the weight) and a coefficient of kinetic friction (which is a measure of how "frictiony" the interface is -- ice or sandpaper).
Kinetic friction stops when the motion stops. Then static friction takes over, which is similir to kinetic but a little stronger, and applies as long as the object stands still. A common mistake is to botch this transition, so that the object winds up oscillating at low speed.
Hi i am trying to write simple game where there is one player and some simple world like trees or some buildings, player can walk having muchine gun and shoot to world object like trees and finally destroy it, game is top-down so i don't need any gravity. Player can hit a lot of bullets and some monster in world can shoot to. SO there can be a lof of bullets in one time on the screen so i need some good tool to make colision detection. Also important is that player can't now walk on other object, like there is a monster and player and they can't exist in the same place (one shouldn't go on another). Can you recoment me some collision detection engine, mayby should I use Farser or better I should write it my self?
simillar to this http://www.youtube.com/watch?v=u8rWomjyTWI
I have one more question, i am still reading about xna since few days, and i know now that if it goes about colision detection we have pixel or square and circle, now: is there any toll or engine which can pare a texture
mappe it into a polygon and check colision?
Farseer is for physics. Use it if you need complex collision reaction. If you simply need if colission then kill player, you don't need such an engine or library.
Did you read the collision example in the App Hub right?
Link: http://create.msdn.com/en-US/education/catalog/tutorial/collision_2d_perpixel_transformed
Thats probably just enough for your purposes.
I have started my first game in corona SDK and have covered a lot but now I'm stuck to a laser functionality for the weapons , have not much idea how can I implement this . any guidance please ? I want to throw laser on fire function which have collision effect other particles.Thanks in advance.
Well that is a fairly broad question so I can only answer that on a high level. First off, look at my sample OOP framework for one way to do object oriented programming in Lua:
http://developer.anscamobile.com/code/object-oriented-sample-game-framework
Now whether you use this approach or some other technique to achieve OOP, what you want to do is create a Laser object and every time the player fires instantiate a Laser object at the weapon's position. Then in the Laser's constructor set an enterFrame listener that will move it forward a little bit every frame. By moving a little bit every frame, the laser will smoothly animate forward.
As for collision, if you are using physics in your game then you could make your lasers into physics objects to handle collisions that way. Alternatively, you can do a simple distance check with the laser against every enemy on screen; when the laser is close to an enemy that means the laser hit that enemy.