|
Post by keywise on Mar 5, 2017 23:10:10 GMT
Out of the box, characters can move forward and backwards and they can move upstairs and downstairs. They can move backwards downstairs, but not backwards upstairs. Small feature, but if there is a small rock behind the character, it would get stuck as it retreats while fighting the evil horde.
I modified vThirdPersonMotor.cs so that the ray to look at the stairs looks backwards when speed is less than zero, and pushes the character upward (instead of down).
Please review the code below for improvements. Hope this helps others.
bool StepOffset() { if (input.sqrMagnitude < 0.1 || !isGrounded) return false;
var forward_backward = 1; if (speed < 0) forward_backward = -1; var hit = new RaycastHit(); Ray rayStep = new Ray((transform.position + new Vector3(0, stepOffsetEnd, 0) + transform.forward * forward_backward * ((_capsuleCollider).radius + 0.05f)), Vector3.down);
if (Physics.Raycast(rayStep, out hit, stepOffsetEnd - stepOffsetStart, groundLayer)) {
if (hit.point.y >= (transform.position.y) && hit.point.y <= (transform.position.y + stepOffsetEnd)) { var heightPoint = new Vector3(transform.position.x, hit.point.y + 0.15f, transform.position.z); transform.position = Vector3.Lerp(transform.position, heightPoint, (speed * forward_backward * stepSmooth) * Time.fixedDeltaTime);
return true; } } return false; }
Side note: I'm really enjoying Melee. Great documentation, videos and code comments. Looking forward to Shooter (hope it has bows for Fantasy games).
|
|
|
Post by Invector on Mar 6, 2017 16:55:32 GMT
hey keywise welcome to the vForum! we actually already fixed this issue, but the update v2.1 is not available yet on the assetstore, here is a quickfix for you: bool StepOffset() { if (input.sqrMagnitude < 0.1 || !isGrounded) return false;
var _hit = new RaycastHit(); var _movementDirection = isStrafing && input.magnitude > 0 ? (transform.right * input.x + transform.forward * input.y).normalized: transform.forward;
Ray rayStep = new Ray((transform.position + new Vector3(0, stepOffsetEnd, 0) + _movementDirection * ((_capsuleCollider).radius + 0.05f)), Vector3.down);
if (Physics.Raycast(rayStep, out _hit, stepOffsetEnd - stepOffsetStart, groundLayer)) { if (_hit.point.y >= (transform.position.y) && _hit.point.y <= (transform.position.y + stepOffsetEnd)) { var _speed = isStrafing ? Mathf.Clamp(input.magnitude, 0, 1) : speed; var velocityDirection = isStrafing ? (_hit.point - transform.position) : (_hit.point - transform.position).normalized; _rigidbody.velocity = velocityDirection * stepSmooth*(_speed * (velocity > 1 ? velocity : 1));
return true; } } return false; }
|
|
|
Post by keywise on Mar 7, 2017 1:28:56 GMT
Thank you. Looking forward to the v2.1 update.
|
|