Making a pivot focused game
Hi, I am trying to make a game similar to I am Bread except I am a stick with 2 sides of pivot points instead of 4. The basic idea here is when I'm gripping one end onto the wall or ground, I can use the other end to swing around and potentially throwing myself over like a ragdoll. The problem I'm facing now is the physics does not work properly with the cylinder object and it can clip through a solid object no matter how thick of the walls and ground on the edge of the play area. Another problem i'm having is the cylinder object does not swing properly in relative to the camera's direction.
Here is my two point pivot script
public class $$anonymous$$agicStick : $$anonymous$$onoBehaviour {
public GameObject leftPivot;
public GameObject rightPivot;
public GameObject mainStick;
public Vector3 center;
public float speed;
public Rigidbody stick;
public Rigidbody leftPivotrb;
public Rigidbody rightPivotrb;
Transform activePivot;
public Rigidbody test;
private void Start()
{
activePivot = leftPivot.transform;
}
void Update ()
{
test.centerOf$$anonymous$$ass = center;
//test.transform.position = activePivot.position;
if (Input.Get$$anonymous$$ouseButtonUp(0) || Input.Get$$anonymous$$ouseButtonUp(1))
{
//stick.is$$anonymous$$inematic = false;
//stick.useGravity = true;
}
if (Input.Get$$anonymous$$ouseButton(0))
{
leftPivot.transform.SetParent(this.transform);
mainStick.transform.SetParent(leftPivot.transform);
rightPivot.transform.SetParent(leftPivot.transform);
activePivot = leftPivot.transform;
//stick.is$$anonymous$$inematic = true;
//stick.useGravity = false;
}
if (Input.Get$$anonymous$$ouseButton(1))
{
rightPivot.transform.SetParent(this.transform);
mainStick.transform.SetParent(rightPivot.transform);
leftPivot.transform.SetParent(rightPivot.transform);
activePivot = rightPivot.transform;
//stick.is$$anonymous$$inematic = true;
//stick.useGravity = false;
}
float inputX = Input.GetAxis("Horizontal");
float inputZ = Input.GetAxis("Vertical");
//activePivot.Rotate(new Vector3(inputX, 0, inputZ));
//assu$$anonymous$$g we only using the single camera:
Camera camera = Camera.main;
//camera forward and right vectors:
Vector3 forward = camera.transform.forward;
Vector3 right = camera.transform.right;
//project forward and right vectors on the horizontal plane (y = 0)
forward.y = 0f;
right.y = 0f;
forward.Normalize();
right.Normalize();
//this is the direction in the world space we want to move:
Vector3 desired$$anonymous$$oveDirection = forward * inputX + right * inputZ;
//movement:
//transform.Translate(desired$$anonymous$$oveDirection * 1 * Time.deltaTime);\
if(activePivot)
{
//activePivot.Rotate(desired$$anonymous$$oveDirection * speed * Time.deltaTime);
test.AddTorque(desired$$anonymous$$oveDirection * speed * Time.deltaTime);
}
}
and here is the 3rd person camera script that I used for the game in case I need to modify to match up with the magic stick controller script.
public class ThirdPersonCamera : $$anonymous$$onoBehaviour {
public float Camera$$anonymous$$oveSpeed = 120.0f;
public GameObject CameraFollowObj;
Vector3 FollowPOS;
public float clampAngle = 80.0f;
public float inputSensitivity = 150.0f;
public GameObject CameraObj;
public GameObject PlayerObj;
public float camDistanceXToPlayer;
public float camDistanceYToPlayer;
public float camDistanceZToPlayer;
public float mouseX;
public float mouseY;
public float finalInputX;
public float finalInputZ;
public float smoothX;
public float smoothY;
public float rotX = 0.0f;
public float rotY = 0.0f;
void Start ()
{
Vector3 rot = transform.localRotation.eulerAngles;
rotX = rot.x;
rotY = rot.y;
Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
Cursor.visible = false;
}
void Update ()
{
//Setup for the rotation of the sticks
//float inputX = Input.GetAxis("Horizontal");
//float inputZ = Input.GetAxis("Vertical");
mouseX = Input.GetAxis("$$anonymous$$ouse X");
mouseY = Input.GetAxis("$$anonymous$$ouse Y");
finalInputX = mouseX;
finalInputZ = mouseY;
rotX += finalInputZ * inputSensitivity * Time.deltaTime;
rotY += finalInputX * inputSensitivity * Time.deltaTime;
rotX = $$anonymous$$athf.Clamp(rotX, -clampAngle, clampAngle);
Quaternion localRotation = Quaternion.Euler(rotX, rotY, 0.0f);
transform.rotation = localRotation;
}
void LateUpdate()
{
CameraUpdater();
}
void CameraUpdater()
{
//Set target object to follow
Transform target = CameraFollowObj.transform;
//move towards the game object that is the target
float step = Camera$$anonymous$$oveSpeed * Time.deltaTime;
transform.position = Vector3.$$anonymous$$oveTowards(transform.position, target.position, step);
}
}