Hello! I am trying to make a gam but have troubles about implementing movement of the character. I want to make a game similar to cube surfers and sky roller(more like cube surfer). So, I want to make player follow a path which is curved prefabs are included and at the same time I want to move the player horizontally by sliding on screen. Exactly like cube surfers. Here is the video how it looks
.
playerRB.MovePosition(playerRB.position += transform.forward * moveSpeed * Time.fixedDeltaTime);
if (Input.GetMouseButton(0) && destructWallBonusBool == false)
{
// playerRB.velocity = Vector3.zero;
NewX = Camera.main.ScreenToViewportPoint (Input.mousePosition).x;
xMotion = (LastX - NewX) * -NavigationMultiplier / Screen.width;
rbPosition = playerRB.position;
rbPosition.x = Mathf.Clamp(playerRB.position.x + xMotion,-1.1f,1.1f);
playerRB.position = rbPosition;
}
LastX = Camera.main.ScreenToViewportPoint(Input.mousePosition).x;
I was using this code to move my character. It works perfectly when player is moving only on z axis (forward) I can’t make it follow the curved paths perfectly. I have tried to insert triggers at the start of the prefabs and I was detecting whether player has entered to left or right turning tiles according to this I was rotating the player with iTween. However, when I enter to curve from inside or with different speed (when the player activates power up for instance) it doesn’t turn correctly. I have also tried to use pathfinder assets and there were some problems too. First of them I am generating levels randomly so I can’t tell the pathfinder which objects it should follow. When I insert waypoints inside prefabs I cant use them because their position is relative to parent so waypoints are not appropriate. Also I cant move my player horizontally when it turns. Lets say player goes on +z axis I can move player horizontally(-x +x with the code that I have posted above) but when player turns 90 degrees right then it starts to move in +x and moving horizontally will be between -z and +z axis however the code above is only for x axis. I thought to create booleans and change the .x variables to .z according to the move direction but maybe there is a better way to do it. I have no idea how I can do this right now. Any help is so much appreciated. Thanks!