How to rotate an object 360 degrees around a sphere with collisions? - c#

I am trying to make the movement of the checker (shown in a circle) equal to its diameter, the move is made only in the free space. (In the game, you can direct where the checker goes) To represent such a movement, we decided to make a outline circle, as a mark that the checker can go there. As an element of game design and simplicity, the outline circle can collide with other objects, preventing it from going into a closed position.
Here's a gameplay video showing how this should work.
To implement this, I made the following checker hierarchy:
Checkers brain
-> Outline circle
The checker's brain is responsible for the player's turns and the move itself. To embody the turns, we change the transform.rotation, and the move is made to the position of the outline circle.
The outline circle is responsible for collisions with other objects, and does not allow you to go to a closed position.
And to make collisions with other objects, we decided to use the Physics.sphereCast.
The decision to use Physics.Spherecast as a bad decision, that's why:
Consider a situation where, in fact, the checker must pass through these walls. But he cannot pass through this wall, since the Physics.SphereCast works like a ray, the ray colliding with the wall tells the outline circle not to pass through the wall.
Can u find a solution for a outline circle that can collide with objects, but which does not work as a ray?
P.S. I tried to change the original position of Physics.SphereCast, but this does not work due to the fact that Physics.SphereCast only shifts towards the origin.

Related

Walking up and down 2d slopes (pixel art)

I'm having an issue where I can't walk up slopes in unity. My art is pixel so I understand the slope is made with a gap of 1 pixel to create the actual slope, but I have no idea how to fix it so I can just walk up and down them normally. Currently, going down them makes it a little bouncy and going up them is impossible unless you jump. Any help would be appreciated! Here is what the slope looks like:
Edit: Collider looks like this but I don't know how to fix it:
Sprites automatically have a polygon collider created for them when imported into the project. This polygon collider drives the tilemap polygon collider shapes.
You can modify the physics shape for a sprite to smooth it out and remove this unwanted when going up a ramp. Custom Physics Shape documentation
Another important thing to note in your specific problem: Often when a character has a "box-like" shape, they will get snagged on edges and small collider deviations. Unless your game's playstyle is based around a box-shaped entity and interactions, it's usually recommended to use a rounded collider for the moving characters (like a 2d or 3d capsule collider).

Unity3D: How to make an object always touch the map mesh?

i am developing a racing game. But it's not your usual racing game, the bike is supposted to always have the Y coordinate of the same value as the closest point on the map mesh, in other words it is ALWAYS touching it.
What i do not want is the Y coordinate to be dependent upon the X and Y position, as there will be 2 (or maybe more floors).
I have absolutely no idea how to implement this. Completly zero. I am rather new to scripting, and this i way out of my league, i don't even know how to start... The map is not a simple plane, so simple maths won't help.
I'll apreaciate any help at all, not necessarily a solution.
Thanks in advance
This idea is an adapted version of #LeoBartkus's
I suggest using 2 raycasts from the bottom of the bike's wheels and using the 2 hits to position and rotate the bike. This allows for an accurate positioning of the bike for all kinds of terrain, except for spikes narrow and tall enough to appear to pierce the bike. Using a single raycast from the bike's center might cause problems if the ground is uneven, like a crater for example

Xna keeping player from overlaping parts of map

I had an idea in my game of having 3 layers to the map, the first being the ground, the second being the roads/grass/etc, and the third being impassable objects such as walls/buildings/lakes/rivers/trees. I have it so the player is centered at the middle of the screen and the layers of the map move in the inverse direction that the player wants to go. I was thinking I would have the different layers that way if the playerModel overlaps whereever something is drawn on the impassableLayer, then the playerModel would shift back. However, as I am new to xna, I don't know how to get the game to recognize that the playerModel is overlapping the impassable objects on the impassableLayer. The impassableLayer obviously only has objects drawn on it, and is empty anywhere there isn't an object. Therefore I can't just say:
if (playerModel.X > impassableLayer.X)
{
impassableLayer.X++;
}
As this would always be true.
Is there a way to tell if an object is overlapping a layer?
What you are looking for is collision detection I belive. You want to keep objects from passing through each other. It isnt as simple as the idea you had. True collision detection will take alot of work, but their are tons of tutorials for it.
Youtube tutorial on per pixel collision
Per-pixel collision on MSDN
Bounding Box Collision
You can always to a search here on the site or google, there are lots of resources for this out there.

Collision depending of side of the rectangle?

Im not intrested in the code for this problem i just want to be pointed in the right direction.
Im using C# XNA if that helps.
Basicaly for my game i am adding collisions for example the player can't walk or fall through stones.. I have the rectangle and i know i use the .intersects comand but would i need to check collision depending on the side of the rectangle here?
I know if the player is falling i can make if playerRectangle intersects stoneRectangle playerY = stopFalling..
But if the rectangle is coliding on the side of the player.. That would be different wouldn't it ?
One simple way of dealing with this is to work out the main axis of penetration, i.e. is the player further into the rectangle horizontally, or vertically. Then, using this information, you'd move the player so they were just touching the rectangle.
i.e. Player bumps into a wall on his right.
Main axis is Horizontal, and he's to the left of the centre of the rectangle, so we know to move him left.
Searching on gamedev.stackexchange.com will give you lots of different collision detection/response options.
If your game is 2D I would recommend using something like FarSeer Physics rather than implementing yourself.
If you are interested in the algorithms it is open source and you can poke around the code to see how they implemented collision detection.

Hiding objects that obscure the player in a 3D scene

I'm designing a 3D game with a camera not entirely unlike that in The Sims and I want to prevent the player character from being hidden behind objects, including walls, pillars and other objects.
One easy way to handle the walls case is to have them face inwards and not have an other side, but that won't cover the other cases at all.
What I had planned is to somehow check for objects that are "in front" of the player, relative to the camera, and hide them - be it by alpha blending or not rendering at all.
One probably not so good idea I had in mind is to scan from the camera to the player in a straight line and see if you hit a non-hidden object, continuing until you reach the player. Unfortunately, I am an almost complete newbie on 3D programming.
Demonstration SVG illustration < that wall panel obscures the player, so it must be hidden. Another unrelated and pretty much already solved problem is removing all three wall panels on that side, which is irrelevant to this question and only caused by the mapping system I came up with.
What I had planned is to somehow check for objects that are "in front" of the player, relative to the camera, and hide them - be it by alpha blending or not rendering at all.
This is a good plan. You'll want to incorporate some kind of bounding volume onto the player, so the entire player (plus a little extra) is visible at all times. Then, simply run the intersection algorithm for each corner of the bounding volume.
Finding which object is at a given point on screen is called picking. Here's an XNA link for you which should direct you to an example. The idea is that you retrieve the 3D point in the game from the 2D point, and then can use standard collision detection methods to work out which object is occupying that space. Then you can elect to render that object differently.
One hack which might suffice if you have trouble with the picking approach is to render the character once as part of the scene, and then render it again at the end at half-alpha on top of everything. That way you can see the whole character and the wall, though you won't see through the wall as such.
One easy way, at least for prototyping, would be to always draw the player after you draw the rest of the scene. This would ensure that the player is rendered on top of anything else in the scene. Crude but effective.
Create a bounding volume from the camera to the extents of the player, determine what objects intersect that volume, and then render them in whatever alternate style you want?
There might be some ultra-clever way to do this, but this seems like the pretty straightforward version, and shouldn't be too much of a perf hit (you're probably doing collision every frame anyway....)
The simplest thing I can think of that should work relatively well is to model all obstacles by a plane perpendicular to your ground (assuming you have a ground.) Roughly assuming everything that is an obstacle is a wall with some height.
Model your player as a point somewhere, and model your camera as another point. The line in 3d that connects these two points lies in a plane that is particularly interesting to you, because if this plane intersects an "obstacle plane" below the height of the obstacle, that means that that obstacle is blocking your view of the player point.
I hope thats somewhat clear. To make this into an algorithm you'd have to implement a general method for determining where two planes intersect (to determine if the obstacle is tall enough to block view.)

Categories

Resources