Creating layers with different Z-Axis positions in SpriteKit? - sprite-kit

The scene
I was wondering about creating
different layers with different Z-Axis values to give more reality like the above picture as it has
1- The green background then
2- The play ground it self then
3- The blurred black trees representing the camera depth of field
So, I thought about Creating the green background then the the black ground with more value of zPosition then the blurred stuff scaled up with more zPosition values, but the problem is when camera moves there is no sense of reality of speed of movement for each layer as they all move together respecting the same positions .
Also I thought about using SceneKit instead as it contains full 3D tools , but the scene is 2D and does not seem to need scenekit.
Thanks in advance as the question seemed too complicated.

Okay, it is figured now.
The answer is gonna be that I put a method that makes the background moves against the camera movement direction with one half or third the camera speed.
As an example
If the camera moves 20 pixels to right , all scene layers seems to be moved 20 pixels to left . So I have to move the background about 8
pixels to right
So all layers seem to be moved 20 pixels to left except that background moved 12 to left, which is slower.

Related

How do I change the color of a circular sector of a 2D stage in Unity?

I am developing a game where a rotating sprite can shine a line onto a black colored and circular arena. I want a circular sector of a certain angle to become white colored, depending on the sprite's orientation.
For example, if the sprite is at 90 degrees, the stage should look like this
What are the most efficient methods to achieve this?
Some details about the game that may be important to know:
The sprite rotates at the center of the stage only and is not mobile.
I'll likely make the arena a n-sided polygon, and the circular sectors will likely be triangular sectors. Then, a circle might overlay this polygon for make the arena look circular. (Not sure how I will be implementing this yet).
One idea I've considered is using cartesian coordinates to create triangles in canvas.
One difficulty I am having conceptually is determining the direction of my rotating sprite.

World to Cube projection Unity

That's the setting:
I have 2 cameras in the game scene. The game must be played in a room with screens on frontal wall and on the floor. To be able to test it I just recreated the 2 screens in Unity. The goal is to make the game immersive, creating the correct illusion as the image on the left.
What I've tried so far (and it kinda worked as you can see from the screenshot) is:
Camera0: goes directly in the frontal display.
Camera1: I created a post processing effect that deforms the output texture to create the correct perspective illusion.
The problem:
The fact that I'm basically working over a texture creates some blurry effect on the borders, because the pixel density is not the same in start and deformed image.
I think the best approach would be to make the deforming transformation happen on the projection matrix of Camera1 instead. But I just failed. Have you any idea on how to approach this problem correctly?
You can let your perspective cameras do the work for you.
Set the fov of the floor camera so that it shows only as much as will fit on the screen.
Then, have the cameras at the same position.
Finally, have the floor camera rotated on the +x axis by half of the sum the fov of both cameras. For example, if the wall camera is fov 80º and the floor fov is 40º, set the floor camera to be rotated by 60º along the x axis.
This will guarantee that the view of the cameras do not overlap, and they will have the correct projection along their surfaces to create the desired illusion.

Unity3D: I want my moving 3D objects to have a consistent shading

I have 2 directional lights in the scene, light 1 is parallel to the Y axis (I want it to make a shadow underneath the sphere), light 2 is parallel to the x axis.
I have some barriers(3d cube objects) that are moving to the left side of the screen( velocity = (-20,0,0) ).
I want the barriers to have a consistent color/shade while moving through the scene. When the object is on the right side of the screen it is darker and as it moves to the left, right before it moves off the screen, it gets brighter. I can't figure out why!
What I've done:
I found if I remove all lights from the scene the effect doesn't happen.
I've removed all other objects from the scene.
In the lighting options I've turned off RealtimeGI and Baked GI.
I've removed the Skybox and turned Ambient Intensity, Reflection Intensity to 0.
Here is the effect to help understand it more:
Barrier
Barrier moved
Thanks if you can help me out!
It looks like it had more to do with the orthogonal camera. I noticed that if I move the camera source point further away, the effect disappeared. My guess is the angle of my camera and how close it was to my main scene intensified the color so it showed it as brighter.
That is my guess anyways, If someone has a better answer please let me know!

How to make a perfect pinch zoom (Unity 3D)

I am searching for a solution to how to make a perfect pinch zoom in Unity by moving the camera along the forward:
Set up:
Horizontal plane centred at the origin with all Game objects.
Perspective camera with FOV 10, offset at (10,10,10) looking down at a 45 degrees angle, so that it looks at the origin (there is also a rotation of 45 degrees around the axis pointing up, to achieve this).
What I need:
When I place two fingers on the screen I am touching two GameObjects with them - so the screen coordinates under the fingers correspond to certain world coordinates. When I make a pinch movement (with moving two fingers or only one) I want the new screen coordinates to correspond to the same world coordinates that were under the fingers at the beginning of the whole interaction.
So to simplify even further - whenever I touch the screen with two fingers, I want the world coordinates corresponding to the screen coordinates under my fingers to always stay under the fingers (allowing a very small margin of error).
An example of this perfect zoom for which I am looking for you can see in the mobile game Boom Beach from Supercell.
I already tried to move the camera along its forward vector and to reposition it and I get pretty good results, but pretty much always the GameObjects underneath ‘slip’ away from under my fingers, that is at some points are no longer underneath them. It would be great if there was a mathematical solution to this, but if it’s necessary to compute the answer (through some search for example) then this is totally fine.
If the setup/scenario is not clear, I could provide some sketches to clarify it a bit more.
Hope someone can help me! :)
I would set up a system that detects when the user is zooming in and out if you are using GameObjects to pinpoint where the fingers are that is easy to do with Vector3.distance. After that, I would make a function that moves the camera closer to your desired zoom level with Vector3.MoveTowards(camera position, desired position, the speed of movement) where I would set "speed of movement" as a mathf.sqrt(vector3.distance(Camera position, Desired position));
as for the "desired position" I would set that Vector3(position) as a fraction of a line between two game objects that represent your maximum and minimum zoom level.
EDIT: with that, you should have a very nice camera system

mouse joint is not working to restrict the ball in the half part of the screen

Hi guys I Am developing the application in cocoas2d using the box 2d frame work but unfortunately
i'm not able to restrict the gray ball in the half screen area of the image shown here
i want that ball not to go opposite part of the screen
I Have Used The b2Mousejoint For to move the ball around the screen
b2PrismaticJointDef restrict on any particular axis
But
i want to restrict on the particular rect area of the screen
You could create your custom distance joint which will restrict global axes of the ball. But it will be hard if you never write your own physics engine.
There are 2 easier ways to implement what you want.
Create 4 static "border" boxes around the area where the ball must stay. Then place the ball and the boxes into one collision group.
However, the response of the "border" boxes will not be instant. Therefore, the ball at high speed will sometimes "sink" into the boxes, then be popped out.
You can correct the position and reset the speed of the ball manually in code when it crosses the bounds of the desired area. But it may lead to the unstable physics simulation.