Question by
rivecal21 · Feb 23, 2018 at 11:16 PM ·
c#character controllercharacter movement
Trying to figure out WallRiding, with Vector3.Cross
Okay, so, I'm using Vector3.Cross to figure out the angle at which I should be moving the character, and the code is essentially this, taped onto a Character Controller: Most of the onTriggerStay and onTriggerExit is left-overs from me scrapping another test I had on doing wallriding. I try to detect for the wall with a 2x2x2 box collider(trigger) around a 1x2x1 CC.
hAxis = Input.GetAxis("Horizontal");
vAxis = Input.GetAxis("Vertical");
if (!Attached)
{
Vector3 MovingTo = transform.rotation * new Vector3(hAxis, verticalVelocity, vAxis) * Speed * Time.deltaTime;
cc.Move(MovingTo);
}
else
{
if (vAxis < 0) Detatch();
Vector3 MovingTo = new Vector3(Cross.x * vAxis, verticalVelocity, Cross.z * vAxis) * Speed * Time.deltaTime;
cc.Move(MovingTo);
}
#endregion
}
#region Assigning Parkour
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Wall" && other.gameObject != LockedWall && !cc.isGrounded)
{
Debug.Log("Hit wall");
RaycastHit hit;
Vector3 dir = (transform.position - other.transform.position).normalized;
Ray ray = new Ray(transform.position, dir);
if (Physics.Raycast(ray, out hit, 2f))
{
Debug.Log("Connected");
Gravity = false;
Attached = true;
Sprinting = true;
Cross = Vector3.Cross(hit.normal, dir);
Cross = Vector3.Cross(Cross, hit.normal);
LockedWall = other.gameObject;
}
}
}
public void OnTriggerStay(Collider other)
{
if (other.gameObject == LockedWall)
{
Sprinting = true;
HangOnTimer -= Time.deltaTime;
if (HangOnTimer >= 0)
{
Debug.Log("Lost grip");
if (UnSprintQueued) Sprinting = false;
}
}
}
public void OnTriggerExit(Collider other)
{
if (other.gameObject == LockedWall && Attached)
{
Debug.Log("Lost connection with wall. Dropping.");
Attached = false;
Gravity = true;
if (UnSprintQueued) Sprinting = false;
}
}
private void Detatch()
{
Attached = false;
Gravity = true;
if (UnSprintQueued) Sprinting = false;
}
#endregion
Comment