0
Will be answered

Side Scroller Lock Axis

itsthehawke 5 months ago in Traversal updated 3 months ago 8

Working on a 2.5D side-scroller at the moment and a problem I keep running into is when a character collides with an object, it can adjust his position on the X axis, which breaks the whole point of side-scroller.


Is there a way to fix the character on a given axis?

Unity version:
2018.4.9f1
Game Creator version:
1.0.5
Under review

Hi;

Not sure I fully understood your question. The If you set the Player's Input to Side-Scroll it should stick to that plane axis. Can you post a screenshot or give some more details about the issue?

The original axis the side-scroller is running on (Green) will get adjusted when I collide (in this case - slide) object that has a slope with high angle and will fall down to the ground on a new, adjusted axis (yellow).

I understand this is a normal behaviour of the Unity physics engine and it makes sense for it to happen, but it limits my possibilities greatly.

Ofcourse Im not putting objects like these into the scene, but this happens with any movable object that the character can collide with + all the ragdolls of enemies that act really crazy on collision with the player, also changing the position on the axis.

This means I can't have any objects with rigidbodies I want my character to collide with + I will need to disable player collision with enemy ragdolls because when Player jumps on an enemy ragdoll, it is going to move him very rapidly and the ragdoll itself will jump around the location like there is a huge force applied to it (possibly another bug?).

Hmm correct. I'll open a ticket and have a look at it. It may be possible to enable/disable axis snapping. Thanks for pointing this out!

Will be answered

Hi Itsthehawkeye;

I've been working on this a big part of this morning, but there isn't a simple solution to solve this. Basically because the conflict between the sliding mechanic and the side-scroll. We could allow the character to snap to an axis, but after the player releases the input, the character would be susceptible to change its axis plane.

We'll leave the ticket open, but this requires a good chunk of our core character movement system to be redone, and it's not a top priority at the moment. Sorry for the bummer. I'll circle back in the future when we have the time to take a closer look.

Hi, I find a workaround, but you need to change the PlayerCharacter.cs, and it may not be highly recommended, but it works!

you must change the UpdateInputSideScroll:

protected virtual void UpdateInputSideScroll(Vector3 axis)
{
Vector3 targetDirection = Vector3.zero;
if (!this.IsControllable()) return;

if (Application.isMobilePlatform || TouchStickManager.FORCE_USAGE)
{
Vector2 touchDirection = TouchStickManager.Instance.GetDirection(this);
targetDirection = axis * touchDirection.x;
}
else
{
targetDirection = axis * Input.GetAxis(AXIS_H);
}

Camera maincam = this.GetMainCamera();
if (maincam == null) return;

this.ComputeMovement(targetDirection);

float invertValue = (this.invertAxis ? -1 : 1);
Vector3 moveDirection = Vector3.Scale(this.direction, axis * invertValue);

Vector3 Xpoint = this.characterLocomotion.GotoPoint; // TRL Add this if you create a new vector3 in the player's character menu, but you can correct the z-line by code directly.

if (this.transform.position.z != Xpoint.z)//TRL-- the player, and all the characters will always go to this z-line
{
moveDirection = moveDirection + new Vector3(0, 0, Xpoint.z - this.transform.position.z);
}//TRL



moveDirection.Normalize();

moveDirection *= this.direction.magnitude;

this.characterLocomotion.SetDirectionalDirection(moveDirection);

}


You can edit the menu and add a float to give to the script the z point or add a vector3 like me. Or if you always work on the same z-line fix it by code, but I don`t recommend do that. The best is to use variables to control the exact position of your character.



just an appreciation, you should use x instead of z but it works the same.

Thanks Tomás! You're right that this works, but there are a few cases where it fails. When the Player (your code only works with the Player but could be changed to work for any character) is locked on a specific plane, it only does when it moves.

When there's no "force" being applied to a character, this can freely drift through ramps. Unfortunately, there's no way for us to easily lock the character on a plane at all times.

Thanks though for pointing this out! :-) 

+1

Thank you for chiming in on the issue gentlemen! Much appreciated.