Unity isometric collision detection - sticking to walls - unity3d

I'm trying to get a decent collision system for my Unity game.
I use OnTriggerEnter and 'Exit to set and unset a 'collided' flag.
I remember the last position of my character before each move.
I then make a move and use the OnTriggerEnter flag to reset the character back to the last position it was at before moving if there was a collision.
The problem is I'm getting stuck to walls quite often and the above method seems overly complex and I'm wondering if I'm missing a more straightforward approach.
Does the above seem like a reasonable strategy for collision detection in an isometric game?
Thanks
s

sure, thats what we did back in the day before unity came in to play,
personally i always used a future ghost, a invisible player that took the step and then told the player if it was okay or not. i didnt like to throw the player around to much.
and you always have to check that the player will not enter the red zone.
Lets say that we jumped inside a red zone and figured out that this is not the place i am suppose to be, so we take a step back, but a step back does not mean we went out of the red zone, we just approced the border a bit.
by using a ghost we ensure that the player never enters the red zone. but a ghost would send back a message to the player saying "no no" to this way.
an example would be we take 1 step inside the red zone, our velocity will bring us 1.1 inside the red zone before the logic to step 1 back kicks in, which means that we will be 0.1 inside the red zone, but our script didnt pick that up because it didnt take the velocity drifting over time in to account.
This was in my experience the most difficult and fun part, going from a cubic move to a more action pack time sensitive one, where you have to take velocity in to consideration, thats why they call it physics engines and not bounding box checking engines. haha.

Related

How can I stop movement while airborne?

I have recently begun working on a game for a uni project and will visit this site probably a lot while encountering problems. This time it's a small but annoying problem.
I am doing a 2D sidecroller so I used the template for it to get me started. I already put in the input for attacking and want that the character stops moving when he does the attack animation. On the ground it works wonderfully, but while airborne the character doesn't completely stop in the air, but is slowly decending during the animation. And I want that the character stops completely.
Here is the Jump Handling from the 2d sidescroller template.
Here is the event tick and where the animation update is called (Ignore the attack counter stuff, doesn't influence)
Here is the Animation update code and the "Stop Movement Immediately" node. It has to be said that I am doing what I learned from a tutorial.
As the name implies, the node should stop movement, which is does in the X Axis, but not completely in the Z Axis. I tried it by saving the location of the Player Character when he attacks while in the air but either I couldn't get the code right or it doesn't work like that.
I would be thankful for advice with this (rather petty) detail.
If your problem is strictly while falling, try setting the gravity to 0 while attacking, create an Event in the animation that fires up when it's finished and then capture it to set the gravity back to the original value.

cloning melee combat from hollow knight

Im coding a platformer game and started cloning hollow knight to get inspiration and training. I'm investigating the behavior of the system during combat and I have some doubts and I'd like to get some help.
As for the hero:
Is there a cooldown between slashes or can you slash as fast as you want?
Is the hitbox of the slash bigger than the slash graphics?
When hit, you get this animation and you are invulnerable for a while. Can it happen that you land on an enemy after the animation and get automatically hit again??
when you hit something you get a small kick back too. Can you hit/be hit during this kick back ?
As for the enemies:
When hit.. do they "jump back"? I mean some kind of kick back animation that moves the enemy away from the hero. I think some do and some don't ..
When being kick back after an initial hit.. can they be hit again or they also get their invulnerable time?
and during this kick back moment can you be hit by them (by just touching them) or do their hit boxes get totally disabled?
can flaying monsters ignore platforms or they find you using something like A* ?
After some experimenting with the game itself and playing some videos in youtube frame by frame I thin that:
There is cooldown, you cannot slash as much as you click.
I would say that the hitbox of the sword is pretty accurate with its sprite
When you hit something you receive a kick back, which is a surprise
but yup, both you and the enemy get opposed kick backs that separate
both of you. You get additional invulnerable time that allow you to
move away from possible involuntary collisions.
As for the enemies:
The do get a kickback but the bigger foes do not.
Is hard to say because the kick back you get in your hero makes it hard to beat the enemy again. I've read that there is a badge that disables your kick back. So I understand they DONT have invulnerable time. Otherwise the badge would be useless.
since you get kick back you cannot be hit by them. Don't know what happen if you wear the badge.
Flaying monsters do collide with the platforms although I doubt they need something as sophisticated as A* but is unclear.

Character Pawn sliding back when picking up objects

I am using Unreal Engine to create a puzzle game. In this game, the player has to pick up a chair/table and place it on a pressure plate in another part of the room in order to unlock a door.
When play testing, picking up objects causes my character to slide back. Once the sliding starts, there is no way to make the character stop sliding. I suspect that this issue may be caused by the object's collision volume entering the character's. However, when I release the object, my character keeps gliding backwards even though by then, the object's collision volume is out of reach.
On my character's blueprint I have locked rotation on all axes, so that it won't randomly start rolling backwards after picking up an object. This solves part of the issue but there is still the gliding that just won't stop.
I am new to UE and I have no idea what may be causing this issue. If you have any previous experience in this or simply want to chime in, please do!
Another alternative fix is to lock the rotation of the collision component in the default pawn that you have or to increase angular damping.
To do so, open the default pawn blueprint and under the physics section, then constraints, lock rotation in the X, Y, and Z axis. Or increase angular damping.
Dont know why this is happening exactly unless we see the actual settings you are using and the BP but when you pick up the object , disable its physics and collision and when you put it back enable it after a delay of 0.5 or 1 second . Hope this helps.

Spherical rigid body will never stop rolling regardless of drag

My problem is that I have a rigid body with a spherical collider and once it starts moving (rolling) it never stops.
I have read other answers here which state that changing the drag (angular and normal) is the answer to this problem but I must be doing something wrong somewhere else. I have been experimenting with this for hours and cant find a solution.
I have moved the drag to a million, still moves but very very slowly. I have moved the angular drag to a million with similar results. I have set the sleepThreshold to a high number. This didnt seem to do anything. I tried changing the friction on the terrain.
I placed the ball on a flat, horizontal plane for all of these tests and applied an impulse to start it moving. It has never come to a stop yet.
There are times when it reaches a certain velocity and then stutters like it is about to stop and then it starts moving at a constant velocity forever, I think I can visibly observe the shift from deceleration to constant velocity. It doesnt make any sense to me at all.
It is my assumption that the ball should stop eventually and that unity, being so advanced, would handle this easily but its possible that I'm missing something due to being so new.

Unity3D: Recalculating collisions after Physics2D.IgnoreLayerCollision()?

I have my "player" gameObject standing atop a platform. He press a combination of keys, I verify that he's standing on the right kind of platform, and I run this code:
Physics2D.IgnoreLayerCollision(playerLayer, plataformLayer);
The intention being that he'd drop down from the platform. Instead, nothing happen immediately. The player is still atop the platform and can move around - only if he gets out of it and tries to get back to it, only at that point will he fall down from it.
So I made a temporary ugly workaround:
Physics2D.IgnoreLayerCollision(playerLayer, plataformLayer);
rigidbody2D.AddForce(transform.up * jump / 1.5f);
This will force the player to jump, making Unity "recalculate" the collisions and the player will, as I want to, pass through the platform. The even weirder part is: if the jump isn't high enough (100 force at 1 mass with 0.5 gravity scale seems to be the minimum), the player will still land on the platform, even though Unity is supposed to be ignoring those collisions.
I also tried pushing the player downwards, both with force and direct velocity, but no luck - he still collides with the platform, he only stops colliding with it after being away from it once.
Also, my player Rigidbody2D Detection Mode is set to Continuous, and I tried setting the platform up in many different ways, with and without a Rigidbody2D.
Any ideas on how to make the player instantly fall down from the platform as soon as collisions start being ignored? Thanks in advance.
I had been having the exact same issue. I have an alternative solution that you may find to your liking.
Rather than disabling or moving the terrain to be ignored, temporarily set the rigidbody2D of your player gameObject to kinematic. This will not cause you to 'drop' through the platform as you would like - but it will allow you to create the illusion that you are, by briefly using transform.Translate (or Vector3.Lerp, if you like) to move your character down via code.
This will disable Rigidbody2D.AddForce, but will still allow for set movement via rigibdody2D.velocity, if that is preferable to manipulating the transform directly.
Ensure the downward velocity lasts only as long as you are Kinematic, and try to let it match the gravity of your game, and it looks pretty seamless.
If you turn the rigidbody back on too quickly, it can (even with ignoreLayers :/ ) still jump back up to the platform - but if you leave it on too long, you can drop through more than one intended one-way platform, or even :O through the bottom of the stage!
This is easily avoided if you can be careful - personally I used both MonoBehaviour.Invoke to set a very short time limit on how long the player would remain Kinematic (about 0.5 seconds), AND I disabled Kinematic as soon as they moved 0.5 units from the point where the 'hopDown' was initiated.
If your gravity / platforms / character scale are vastly different than my own, you may have to experiment with some different numbers.
This has been my first attempt at an answer on stackoverflow, so I hope it has been helpful!
One easy way to do this is after calling
Physics2D.IgnoreLayerCollision(playerLayer, plataformLayer);
You reset the player's layer:
player.gameObject.layer = playerLayer;
It's sounds like you have covered a ton of possible solutions to this problem before coming here so, good job there. I listed a few alternative ideas below. I hope they help. Good luck!
Remove the collision object from the platform itself.
Offset the collision object to be in some remote location so it will not interact with the player. Offsetting the object may cause the collision to have a similar reaction to the jump you mentioned.