Character Movement on Cylinder Surface
Hey guys, i couldnt find (honestly) much material on the project im making for class. I want to build a Resogun style game (https://www.youtube.com/watch?v=1slK9nVE9Cc).
Can someone point me to a tutorial or maybe a script to make the character movement on a cylinder surface? Just like in the game... i created a solid cylinder on the origin (0, 0, 0) scaled to (100, 25, 100) to have plenty of space for the ship to move.
How to i move only to the sides and up/down? (in my case z and y axis)? Im messing with quartenions but having difficulty. I could figure how to move on z and y but since in my code i set x to 0.0f, it doenst follow the cylinder surface. What should i set the "x" to?
How to prevent the player to go any further from the top "y" and bottom "y" coordinate. Should i just make a invisible solid object on both limits?
How to make the ship face back and front and rotate when changing the z axis direction? (remeber the ship faces z direction + and -, and its side faces the cylinder surface. I saw a prety good exemple of what i want on youtube (https://www.youtube.com/watch?v=hTANIDnZdZE).
Thanks a lot guys!
My PlayerController code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float moveSpeed = 15;
private Vector3 moveDir;
void Update () {
moveDir = new Vector3(0.0f, Input.GetAxisRaw("Vertical"), Input.GetAxisRaw("Horizontal")).normalized;
}
void FixedUpdate () {
GetComponent<Rigidbody>().MovePosition(GetComponent<Rigidbody>().position + transform.TransformDirection(moveDir) * moveSpeed * Time.deltaTime);
}
}
I would split the movment. Place an empty gameobject at the center of the cylinder. Attach your spaceship to it. Apply vertical movement by altering the local.y position. restrict it to the bounds you need. Every other movement you should convert to angles by which you rotate the center transform, which in turn moves the spaceship in a circle around the cylinder.