Unity eye to follow the player 2D - c#

I'm currently working on a narrative game and don't know how to accomplish something. The game is a 2D platformer so everything is build with sprites. I have a scene with trees and the trees have eyes, I want the eyes to follow the player along, but the "pupils" need to stay within the "holes" of the tree. I have made separate sprites for both the hole in the tree as well as the pupils of the eye's. I would prefer to write it in c# :).
I have also added a concept screenshot, so you can get an impression about what i'm trying to accomplish.
http://imgur.com/pGCV8Uy
Many thanks to the person who can explain to me how to accomplish this!

Well I suppose you could use a joint to restrict the yellow pupils to stay within the holes of the eyes.
Then you could use C# to calculate the relative Vector between the character and the pupil. Guide the pupil to go in the direction of the Vector, and it will be restricted by the joint to stay in the eye. The would result in the pupil always pointing in the direction of the character while staying in the eye, which is what you want.

Related

How can I make this sprite cull at the nearest wall?

Im working on a build-engine style unity game, and something regarding my explosion sprites has really been bugging me. My map is split into several pieces for both occlusion culling and my method for dimming certain sections. I want this explosion sprite to only render up until the nearest wall to its left and right, I thought that maybe sprite masks would work but I can't think of any way to implement this in code.

How to make dynamic shape adjustment to another shape

Hi guys i was wondering how to create a shape adjustment with two objects which specifically could be described as the independent cells, one of which is static, and the second one is dynamic and surrounded by "plasma". The movement of the active object must be controllable by the user (WSAD). Collision of the active object with the static one causes the static object to be swallen, though doesn't change it's position stays in place all the time. As the active object moves, passes the swallen object and troughts it out.
See the image below:
Player character
When it comes close enough to pink enemy it's starting to swallow it (surround by yellow thing)
Pink enemy is completely sourrounded when red circle is in the centre of both.
When it leaves enemy it takes off the yellow thing
I was wondering what is the simplest way to do it. I've been thinking about cloth, physics joints, mesh substraction (is it even possible?), some kind of animation... I don't have much time to do it. Can you show me the simplest way. Which tools and approach should i use? I'm not asking for full code or full solution only for some tips.
Tim Hunter mentioned a wonderful way, most perfect in 3D.
You can use another approach in 2D :
Inside OnCollisionEnter2D try finding hit points using Collision2D.contacts . See this reference .
Create some particle effect there.
Disable the enemy
Now play swallowing animation of the player.
At animation end, enable enemy again.
Maybe calculation is little tricky, still efficient.

How to make object follow waypoints to a center point?

Im not sure how to approach this and looking for suggestions - I have a moving box (moved by the user) with paths cut into it, and a character that traverses the paths. The moving box moves as well as rotates.
At all times, I need the character to follow the paths (NOT walk thru walls) to get back to a point on the box that is
facing the screen (even when the box rotates)
Middle of the screen (even as the box moves up/down)
Here the circle scribble is the character:
What would this be called/any approaches? Is this a waypoint system or something more complex?
A nav mesh would be better if you wish to make a more complex AI for the other character say if you wanted the character to chase the player. If your route is predefined then using waypoints will be the most efficient way of creating what you want in this scenario. Here is a good tutorial by Brackeys of how to implement waypoints.
https://www.youtube.com/watch?v=aFxucZQ_5E4

XNA 2D Transformation

I have actually the following map (isometric projection), and I can move/zoom/rotate without problem with matrix transformations (SpriteBatch): picture.
And I wanted to know if it was possible (if so, how), to get the following result, without referring to 3D: picture.
All suggestions are welcome. Thank you in advance. :)
Its going to be a huge pain in the ass, especially but I think it is at least possible if you don't change the viewing angle.
Some ideas:
Make each tile its own little image unit.
The more far back the tile is from the camera, lower its layer priority when you draw it so that it gets blocked by tiles in front of it. Also you will have to figure out an algorithm that correctly sizes the tiles based on their distance. This algorithm will have to be more and more precise the closer you want to get the tiles, but there should be some mathematical/geometric formula that can do it automatically.
You quite literally CANNOT rotate the camera at all, unless you want to have separate sprites for every single angle for every single tile.

Collision detection 2D between rectangles

I am writting a collision detection engine for my game and I have some problems.
Indeed, since I have several fixed rectangle and one moving (the player), I need to know which side of the fixed one was collided at first by the player, to replace him correctly.
The fixed rectangle are NOT in a grid so they can be placed anywhere on the map and they can have diffents size. They are not rotated.
The player class stores it's direction vector.
Any idea?
KiTe
In a nutshell:
You'll compare the Y and X components of the bounding rectangles to eachother to check for a collision. If the top(Y) of the player is less than the bottom of an enemy then you don't need to check anymore because it's not possible that they're colliding. If the right(X) side of the player is less than the left side of the enemy then they can't be colliding. It would help to define top, right, bottom, left of each object you intend to check inside the class. This will allow you to know which side is hit also. This should be enough to get you thinking and experimenting.
Have fun!
The name is "Axis-Aligned Bounding Box" collision detection.
Now you know the name, you can Google for the rest.
thanks to both of you for your help.
I've heard about AABB, but at first sight it didnt seem to fit to my needs (since I didn't understand it well).
But after writing down everything on papper, the solution I found appeared to be exactly the same as AABB !

Categories