could someone tell me why everything vibrates when the camera in my game moves? - camera

I'm not sure why, but for some reason whenever the camera in my game moves, everything but the character it's focusing on does this weird thing where they move like they should, but they almost vibrate and you can see a little trail of the back of the object, although it's very small. can someone tell me why this is happening? here's the code:
x+= (xTo-x)/camera_speed_width;
y+= (yTo-y)/camera_speed_height;
x=clamp(x, CAMERA_WIDTH/2, room_width-CAMERA_WIDTH/2);
y=clamp(y, CAMERA_HEIGHT/2, room_height-CAMERA_HEIGHT/2);
if (follow != noone)
{
xTo=follow.x;
yTo=follow.y;
}
var _view_matrix = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
var _projection_matrix = matrix_build_projection_ortho(CAMERA_WIDTH,CAMERA_HEIGHT,-10000,10000)
camera_set_view_mat(camera,_view_matrix);
camera_set_proj_mat(camera,_projection_matrix);

I can think of 2 options:
Your game runs on a low Frames Per Second (30 or lower), a higher FPS will render moving graphics smoother (60 FPS been the usual minimum)
another possibility is that your camera is been set to a target multiple times, perhaps one part (or block code) follows the player earlier than the other. I think you could also let a viewport follow an object in the room editor, perhaps that's set as well.
Try and see if these options will help you out.

If your camera is low-resolution, you should consider rounding/flooring your camera coordinates - otherwise the instances are (relative to camera) at fractional coordinates, at which point you are at mercy of GPU as to how they will be rendered. If the instances themselves also use fractional coordinates, you are going to get wobble as combined fractions round to one or other number.

Related

Unity2d; How to raise(lift) camera during game mode at a fixed y axis minimum

I may be making this harder than what it really is, but I am also pretty new to developing games. Currently I am making a practice scene to get back used to the unity engine as I have not had time to use it since last summer. My issue is that I can not figure out how to lift the camera in game mode. Notice my photo below, and how much of the "underground" is showing. I want to raise the camera to keep it at the very least a specific y axis value, so that I can make less of the ground visible, and more of the background visible. If I am over complicating this, please also let me know. Thank you
If main camera is still then just lift the camera in scene view you can see changes in game view.
Or if camera moves with respect to player then you have to use a script and attach it to camera and get a reference of player transform in the script and according to the player position change position of the camera. Add an offset value in y component of the camera.

Changing game size in Phaser dynamically

I'm building a game in which I can enter a building, which I'm handling via states. In other words, when my character overlaps with the door, the program starts a new state in which the interior of the building is built. Now, I want the interior to have smaller dimensions than the world, so I want to change the game size when I start this new state.
I tried this:
create: function()
{
//game size was 1000x700, I want to scale it to 700x450
game.width = 700;
game.height = 450;
//rest of creation code...
}
I also tried things like changing camera bounds, world bounds, world size, but method above shows the most promise.
The problem, however, is that the resize for some reason does not show until I click away from my browser tab and back. Calling game.width in the console yields 700 at all times, but it doesn't show it as such until tabbing out and back.
On top of that, the contents of the game (floor, furniture) are scaled down when the game resizes, defeating the purpose. I don't understand why it would, since there's no scaling anywhere in my code.
Any help would be greatly appreciated.
Edit:
I just saw that you were the one asking the question I linked to, so I guess the question is solved :D
I had a similar problem some time ago. As you described yourself: what you are doing is a resize! So the game resizes itself which means the same as re-scaling everything in the game.
if you want to cut the game smaller you can simply use
game.scale.setGameSize(700, 450);.
(see this post if you need more information)
As additional information: I later had problems with cutting the game size equally on all sides, so if you should come to face the same problem, have a look at this post

Special Kind of ScrollView

So I have my game, made with SpriteKit and Obj-C. I want to know a couple things.
1) What is the best way to make scroll-views in SpriteKit?
2) How do I get this special kind of scroll-view to work?
The kind of scroll-view I'd like to use is one that, without prior knowledge, seems like it could be pretty complicated. You're scrolling through the objects in it, and when they get close to the center of the screen, they get larger. When they're being scrolled away from the center of the screen, they get smaller and smaller until, when their limit is met, they stop minimizing. That limitation goes for getting bigger when getting closer to the center of the screen, too.
Also, I should probably note that I have tried a few different solutions for cheap remakes of scroll views, like merely adding the objects to a SKNode and moving the SKNode's position relative to the finger's, and its movement . . . but that is not what I want. Now, if there is no real way to add a scroll-view to my game, this is what I'm asking. Will I simply have to do some sort of formula? Make the images bigger when they get closer to a certain spot, and maybe run that formula each time -touchesMoved is called? If so, what sort of formula would that be? Some complicated Math equation subtracting the node's position from the center of the screen, and sizing it accordingly? Something like that? If that's the case, will you please give me some smart Math formula to do that, and give it to me in code (possibly a full-out function) format?
If ALL else fails, and there is no good way to do this, what would some other way be?
It is possible to use UIScrollViews with your SpriteKit scenes, but there's a bit of a workaround involved there. My recommendation is to take a look at this github project, that is what I based my UIScrollView off of in my own projects. From the looks of it, most of the stuff you'd want has actually been converted to Swift now, rather than Objective-C when I first looked at the project, so I don't know how that'll fare with you.
The project linked above would result in your SKScene being larger than the screen (I assume that is why it would need to be scrolled), so determining what is and is not close to the center of the scene won't be difficult. One thing you can do is use the update loop in SpriteKit to constantly update the size of Sprites (Perhaps just those on-screen) based on their distance from a fixed, known center point. For instance, if you have a screen of width and height 10, then the midpoint would be x,y = 5,5. You could then say that size = 1.0 - (2 * distance_from_midpoint). Given you are at the midpoint, the size will be 1.0 (1.0 - (2 * 0)), the farther away you get, the smaller your scale will be. This is a crude example that does not account for a max or min fixed size, and so you will need to work with it.
Good luck with your project.
Edit:
Alright, I'll go a bit out of my way here and help you out with the equation, although mine still isn't perfect.
Now, this doesn't really give you a minimum scale, but it will give you a maximum one (Basically at the midpoint). This equation here does have some flaws though. For one, you might use this to find the x and y scale of your objects based on their distance from a midpoint. However, you don't really want two different components to your scale. What if your Sprite is right next to the x midpoint, and the x_scale spits out 0.95? Well, that's almost full-sized. But if it is far away from the midpoint on the y axis, and it gives you a y scale of, say 0.20, then you have a problem.
To solve that, I just take the magnitude or hypotenuse of the vector between the current coordinate and the coordinate of the current sprite. That hypotenuse gives me an number that represents the true distance, which eliminates the problem with clashing scale values.
I've made an example of how to calculate this inside Google's Go-Playground, so you can run the code and see what different scales you get based on what coordinate you plug in. Also, the equation used in there is slightly modified, It's basically the same thing as above but without the maxscale - part of the front part of the equation.
Hope this helps out!
Embedding Attempt:
see this code in play.golang.org

Adjust speed of hand cursor in kinect region

I am using Kinect SDK 1.8, i am using default Kinect control. KinectRegion to display hand cursor of Microsoft.Kinect.Toolkit.Controls. But hand cursor is too fast and sensitive. i wanted it to be make it slow down, so that end user of my Kinect app can control that cursor easily on screen. i tried out with the AccelerometerGetCurrentReading() (Line No. 962) and also tried out with the KinectAdaptor.cs (Line No. 299) handPointer.X, Y, Z, but didn't get any success. can some one help on it.
I already gone through the Human interface guide and also tried Kinect interaction demo, but it is work with the same speed of hand cursor, as is it working in my app.
Is there any work around for this?
Or any property to control the speed of hand cursor in PHIZ, come in future release.
I am not aware of any built-in solution for this. However, there are a couple tricks you could do if you're willing to produce some code in the middle.
You say there are two problems
The Kinect Cursor is too fast (i.e. for the amount your hand moves in the real world, the cursor moves too much on the screen.
The Kinect Cursor is too sensitive. (i.e. the movements of the Kinect are hard to control)
For #1, I am not sure if the cursor->screen mapping is absolute. If you put your hand at the edges of the Kinect's vision, does it match the edge of your computer screen? If so, it could be hard to adjust the speed of the cursor (also called gain). One hack-y solution can just be to move your body farther away from the screen, so that your movements in physical space are larger.
For #2, you could implement a basic low-pass filter. This means that large motions "pass through" the filter, but small, jittery motions are ignored. The simplest way to do this is have something like a running average.
Point CurrentKinectPoint; //this is the filtered position of the mouse cursor
const double FILTER_FACTOR = 0.5;
void UpdateKinectControlPoint(Point NewPoint) {
CurrentKinectPoint.x = CurrentKinectPoint.x * FILTER_FACTOR + NewPoint.x * (1 - FILTER_FACTOR);
CurrentKinectPoint.y = CurrentKinectPoint.y * FILTER_FACTOR + NewPoint.y * (1 - FILTER_FACTOR);
}
I hope this is helpful, at the high-level at least.

XNA model translation is bizzarre

When using Matrix.CreateTranslation(x,y,z) I get bizarre results. I have tested using fixed values, one variable at a time and have determined the following:
When altering the X coordinates, the model moves from the top left corner to the bottom right corner.
When altering the Y coordinates, the model moves up and down as it should.
I do not plan to alter the Z coordinates, but because of the nature of my program I can't figure out exactly what it does.
I have my model drawn. Rotation works fine. I am performing my translations in the correct order (at least I think): scale * rotation * translation.
I think the problem lies in my camera settings, but I have no idea exactly what the problem is. I am trying to create a top-down-style RTS camera.
Here are my camera settings:
campos = new Vector3(5000.0F, 5000.0F, 5000.0F)
effect.View = Matrix.CreateLookAt(campos, Vector3.Down, Vector3.Up)
I can provide more information as needed.
The second argument of Matrix.CreateLookAt is not the direction the camera is facing, but the targeted point.
If you try to make the camera look down, use
Matrix.CreateLookAt(campos, campos + Vector3.Down, Vector3.Forward)
This will tell the camera to always look at the point one unit below the camera.
Your translation probably doesn't work well because the camera is not looking at the point you want it to, and therefore looks like the model is moving diagonally.