Preciso de algúem para modificar um script, negociaremos o valor $
2 participantes
Página 1 de 1
Preciso de algúem para modificar um script, negociaremos o valor $
- Código:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum Status { idle, moving, crouching, sliding, climbingLadder, wallRunning, grabbedLedge, climbingLedge, vaulting }
public class PlayerController : MonoBehaviour
{
public Status status;
[SerializeField]
private LayerMask vaultLayer;
[SerializeField]
private LayerMask ledgeLayer;
[SerializeField]
private LayerMask ladderLayer;
[SerializeField]
private LayerMask wallrunLayer;
GameObject vaultHelper;
Vector3 wallNormal = Vector3.zero;
Vector3 ladderNormal = Vector3.zero;
Vector3 pushFrom;
Vector3 slideDir;
Vector3 vaultOver;
Vector3 vaultDir;
PlayerMovement movement;
PlayerInput playerInput;
AnimateLean animateLean;
bool canInteract;
bool canGrabLedge;
bool controlledSlide;
float rayDistance;
float slideLimit;
float slideTime;
float radius;
float height;
float halfradius;
float halfheight;
int wallDir = 1;
private void Start()
{
CreateVaultHelper();
playerInput = GetComponent<PlayerInput>();
movement = GetComponent<PlayerMovement>();
if (GetComponentInChildren<AnimateLean>())
animateLean = GetComponentInChildren<AnimateLean>();
slideLimit = movement.controller.slopeLimit - .1f;
radius = movement.controller.radius;
height = movement.controller.height;
halfradius = radius / 2f;
halfheight = height / 2f;
rayDistance = halfheight + radius + .1f;
}
/******************************* UPDATE ******************************/
void Update()
{
//Updates
UpdateInteraction();
UpdateMovingStatus();
//Check for movement updates
CheckSliding();
CheckCrouching();
CheckForWallrun();
CheckLadderClimbing();
UpdateLedgeGrabbing();
CheckForVault();
//Add new check to change status right here
//Misc
UpdateLean();
}
void UpdateInteraction()
{
if (!canInteract)
{
if (movement.grounded || movement.moveDirection.y < 0)
canInteract = true;
}
else if ((int)status >= 6)
canInteract = false;
}
void UpdateMovingStatus()
{
if ((int)status <= 1)
{
status = Status.idle;
if (playerInput.input.magnitude > 0.02f)
status = Status.moving;
}
}
void UpdateLean()
{
if (animateLean == null) return;
Vector2 lean = Vector2.zero;
if (status == Status.wallRunning)
lean.x = wallDir;
if (status == Status.sliding && controlledSlide)
lean.y = -1;
else if (status == Status.grabbedLedge || status == Status.vaulting)
lean.y = 1;
animateLean.SetLean(lean);
}
/*********************************************************************/
/******************************** MOVE *******************************/
void FixedUpdate()
{
switch (status)
{
case Status.sliding:
SlideMovement();
break;
case Status.climbingLadder:
LadderMovement();
break;
case Status.grabbedLedge:
GrabbedLedgeMovement();
break;
case Status.climbingLedge:
ClimbLedgeMovement();
break;
case Status.wallRunning:
WallrunningMovement();
break;
case Status.vaulting:
VaultMovement();
break;
default:
DefaultMovement();
break;
}
}
void DefaultMovement()
{
if (playerInput.run && status == Status.crouching)
Uncrouch();
movement.Move(playerInput.input, playerInput.run, (status == Status.crouching));
if (movement.grounded && playerInput.Jump())
{
if (status == Status.crouching)
Uncrouch();
movement.Jump(Vector3.up, 1f);
playerInput.ResetJump();
}
}
/*********************************************************************/
/****************************** SLIDING ******************************/
void SlideMovement()
{
if (movement.grounded && playerInput.Jump())
{
if (controlledSlide)
slideDir = transform.forward;
movement.Jump(slideDir + Vector3.up, 1f);
playerInput.ResetJump();
slideTime = 0;
}
movement.Move(slideDir, movement.slideSpeed, 1f);
if (slideTime <= 0)
{
if (playerInput.crouching)
Crouch();
else
Uncrouch();
}
}
void CheckSliding()
{
//Check to slide when running
if(playerInput.crouch && canSlide())
{
slideDir = transform.forward;
movement.controller.height = halfheight;
controlledSlide = true;
slideTime = 1f;
}
//Lower slidetime
if (slideTime > 0)
{
status = Status.sliding;
slideTime -= Time.deltaTime;
}
if (Physics.Raycast(transform.position, -Vector3.up, out var hit, rayDistance))
{
float angle = Vector3.Angle(hit.normal, Vector3.up);
if (angle > slideLimit && movement.moveDirection.y < 0)
{
Vector3 hitNormal = hit.normal;
slideDir = new Vector3(hitNormal.x, -hitNormal.y, hitNormal.z);
Vector3.OrthoNormalize(ref hitNormal, ref slideDir);
controlledSlide = false;
status = Status.sliding;
}
}
}
bool canSlide()
{
if (!movement.grounded) return false;
if (playerInput.input.magnitude <= 0.02f || !playerInput.run) return false;
if (slideTime > 0 || status == Status.sliding) return false;
return true;
}
/*********************************************************************/
/***************************** CROUCHING *****************************/
void CheckCrouching()
{
if (!movement.grounded || (int)status > 2) return;
if(playerInput.crouch)
{
if (status != Status.crouching)
Crouch();
else
Uncrouch();
}
}
void Crouch()
{
movement.controller.height = halfheight;
status = Status.crouching;
}
void Uncrouch()
{
movement.controller.height = height;
status = Status.moving;
}
/*********************************************************************/
/************************** LADDER CLIMBING **************************/
void LadderMovement()
{
Vector3 input = playerInput.input;
Vector3 move = Vector3.Cross(Vector3.up, ladderNormal).normalized;
move *= input.x;
move.y = input.y * movement.walkSpeed;
bool goToGround = false;
goToGround = (move.y < -0.02f && movement.grounded);
if (playerInput.Jump())
{
movement.Jump((-ladderNormal + Vector3.up * 2f).normalized, 1f);
playerInput.ResetJump();
status = Status.moving;
}
if (!hasObjectInfront(0.05f, ladderLayer) || goToGround)
{
status = Status.moving;
Vector3 pushUp = ladderNormal;
pushUp.y = 0.25f;
movement.ForceMove(pushUp, movement.walkSpeed, 0.25f, true);
}
else
movement.Move(move, 1f, 0f);
}
void CheckLadderClimbing()
{
if (!canInteract)
return;
//Check for ladder all across player (so they cannot use the side)
bool right = Physics.Raycast(transform.position + (transform.right * halfradius), transform.forward, radius + 0.125f, ladderLayer);
bool left = Physics.Raycast(transform.position - (transform.right * halfradius), transform.forward, radius + 0.125f, ladderLayer);
if (Physics.Raycast(transform.position, transform.forward, out var hit, radius + 0.125f, ladderLayer) && right && left)
{
if (hit.normal != hit.transform.forward) return;
ladderNormal = -hit.normal;
if (hasObjectInfront(0.05f, ladderLayer) && playerInput.input.y > 0.02f)
{
canInteract = false;
status = Status.climbingLadder;
}
}
}
/*********************************************************************/
/**************************** WALLRUNNING ****************************/
void WallrunningMovement()
{
Vector3 input = playerInput.input;
float s = (input.y > 0) ? input.y : 0;
Vector3 move = wallNormal * s;
if (playerInput.Jump())
{
movement.Jump(((Vector3.up * (s + 0.5f)) + (wallNormal * 2f * s) + (transform.right * -wallDir * 1.25f)).normalized, s + 0.5f);
playerInput.ResetJump();
status = Status.moving;
}
if (!hasWallToSide(wallDir) || movement.grounded)
status = Status.moving;
movement.Move(move, movement.runSpeed, (1f - s) + (s / 4f));
}
void CheckForWallrun()
{
if (!canInteract || movement.grounded || movement.moveDirection.y >= 0)
return;
int wall = 0;
if (hasWallToSide(1))
wall = 1;
else if (hasWallToSide(-1))
wall = -1;
if (wall == 0) return;
if(Physics.Raycast(transform.position + (transform.right * wall * radius), transform.right * wall, out var hit, halfradius, wallrunLayer))
{
wallDir = wall;
wallNormal = Vector3.Cross(hit.normal, Vector3.up) * -wallDir;
status = Status.wallRunning;
}
}
bool hasWallToSide(int dir)
{
//Check for ladder in front of player
Vector3 top = transform.position + (transform.right * 0.25f * dir);
Vector3 bottom = top - (transform.up * radius);
top += (transform.up * radius);
return (Physics.CapsuleCastAll(top, bottom, 0.25f, transform.right * dir, 0.05f, wallrunLayer).Length >= 1);
}
/*********************************************************************/
/******************** LEDGE GRABBING AND CLIMBING ********************/
void GrabbedLedgeMovement()
{
if (playerInput.Jump())
{
movement.Jump((Vector3.up - transform.forward).normalized, 1f);
playerInput.ResetJump();
status = Status.moving;
}
movement.Move(Vector3.zero, 0f, 0f); //Stay in place
}
void ClimbLedgeMovement()
{
Vector3 dir = pushFrom - transform.position;
Vector3 right = Vector3.Cross(Vector3.up, dir).normalized;
Vector3 move = Vector3.Cross(dir, right).normalized;
movement.Move(move, movement.walkSpeed, 0f);
if (new Vector2(dir.x, dir.z).magnitude < 0.125f)
status = Status.idle;
}
void CheckLedgeGrab()
{
//Check for ledge to grab onto
Vector3 dir = transform.TransformDirection(new Vector3(0, -0.5f, 1).normalized);
Vector3 pos = transform.position + (Vector3.up * height / 3f) + (transform.forward * radius / 2f);
bool right = Physics.Raycast(pos + (transform.right * radius / 2f), dir, radius + 0.125f, ledgeLayer);
bool left = Physics.Raycast(pos - (transform.right * radius / 2f), dir, radius + 0.125f, ledgeLayer);
if (Physics.Raycast(pos, dir, out var hit, radius + 0.125f, ledgeLayer) && right && left)
{
Vector3 rotatePos = transform.InverseTransformPoint(hit.point);
rotatePos.x = 0; rotatePos.z = 1;
pushFrom = transform.position + transform.TransformDirection(rotatePos); //grab the position with local z = 1
rotatePos.z = radius * 2f;
Vector3 checkCollisions = transform.position + transform.TransformDirection(rotatePos); //grab it closer now
//Check if you would be able to stand on the ledge
if (!Physics.SphereCast(checkCollisions, radius, Vector3.up, out hit, height - radius))
{
canInteract = false;
status = Status.grabbedLedge;
}
}
}
void UpdateLedgeGrabbing()
{
if (movement.grounded || movement.moveDirection.y > 0)
canGrabLedge = true;
if (status != Status.climbingLedge)
{
if (canGrabLedge && !movement.grounded)
{
if (movement.moveDirection.y < 0)
CheckLedgeGrab();
}
if (status == Status.grabbedLedge)
{
canGrabLedge = false;
Vector2 down = playerInput.down;
if (down.y == -1)
status = Status.moving;
else if (down.y == 1)
status = Status.climbingLedge;
}
}
}
/*********************************************************************/
/***************************** VAULTING ******************************/
void VaultMovement()
{
Vector3 dir = vaultOver - transform.position;
Vector3 localPos = vaultHelper.transform.InverseTransformPoint(transform.position);
Vector3 move = (vaultDir + (Vector3.up * -(localPos.z - radius) * height)).normalized;
if(localPos.z > halfheight)
{
movement.controller.height = height;
status = Status.moving;
}
movement.Move(move, movement.runSpeed, 0f);
}
void CheckForVault()
{
if (status == Status.vaulting) return;
float checkDis = 0.05f;
checkDis += (movement.controller.velocity.magnitude / 16f); //Check farther if moving faster
if(hasObjectInfront(checkDis, vaultLayer) && playerInput.Jump())
{
if (Physics.SphereCast(transform.position + (transform.forward * (radius - 0.25f)), 0.25f, transform.forward, out var sphereHit, checkDis, vaultLayer))
{
if (Physics.SphereCast(sphereHit.point + (Vector3.up * halfheight), radius, Vector3.down, out var hit, halfheight - radius, vaultLayer))
{
//Check above the point to make sure the player can fit
if (Physics.SphereCast(hit.point + (Vector3.up * radius), radius, Vector3.up, out var trash, height-radius))
return; //If cannot fit the player then do not vault
vaultOver = hit.point;
vaultDir = transform.forward;
SetVaultHelper();
canInteract = false;
status = Status.vaulting;
movement.controller.height = radius;
}
}
}
}
void CreateVaultHelper()
{
vaultHelper = new GameObject();
vaultHelper.transform.name = "(IGNORE) Vault Helper";
}
void SetVaultHelper()
{
vaultHelper.transform.position = vaultOver;
vaultHelper.transform.rotation = Quaternion.LookRotation(vaultDir);
}
/*********************************************************************/
bool hasObjectInfront(float dis, LayerMask layer)
{
Vector3 top = transform.position + (transform.forward * 0.25f);
Vector3 bottom = top - (transform.up * halfheight);
return (Physics.CapsuleCastAll(top, bottom, 0.25f, transform.forward, dis, layer).Length >= 1);
}
}
- Código:
using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
[Serializable]
public class SomPassos{
public string tagchao;
public AudioClip[] audios;
}
namespace UnityStandardAssets.Characters.FirstPerson
{
[RequireComponent(typeof (CharacterController))]
[RequireComponent(typeof (AudioSource))]
public class FirstPersonController : MonoBehaviour
{
[SerializeField] private bool m_IsWalking;
[SerializeField] private float m_WalkSpeed;
[SerializeField] private float m_RunSpeed;
[SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten;
[SerializeField] private float m_JumpSpeed;
[SerializeField] private float m_StickToGroundForce;
[SerializeField] private float m_GravityMultiplier;
[SerializeField] private MouseLook m_MouseLook;
[SerializeField] private bool m_UseFovKick;
[SerializeField] private FOVKick m_FovKick = new FOVKick();
[SerializeField] private bool m_UseHeadBob;
[SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
[SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
[SerializeField] private float m_StepInterval;
[Space(10)]
public AudioClip[] SomPassosPadrao;
public SomPassos[] SomDosPassos;
string tagAtual;
[Space(10)]
[SerializeField] private AudioClip m_JumpSound; // the sound played when character leaves the ground.
[SerializeField] private AudioClip m_LandSound; // the sound played when character touches back on ground.
private Camera m_Camera;
private bool m_Jump;
private float m_YRotation;
private Vector2 m_Input;
private Vector3 m_MoveDir = Vector3.zero;
private CharacterController m_CharacterController;
private CollisionFlags m_CollisionFlags;
private bool m_PreviouslyGrounded;
private Vector3 m_OriginalCameraPosition;
private float m_StepCycle;
private float m_NextStep;
private bool m_Jumping;
private AudioSource m_AudioSource;
// Use this for initialization
private void Start()
{
m_CharacterController = GetComponent<CharacterController>();
m_Camera = Camera.main;
m_OriginalCameraPosition = m_Camera.transform.localPosition;
m_FovKick.Setup(m_Camera);
m_HeadBob.Setup(m_Camera, m_StepInterval);
m_StepCycle = 0f;
m_NextStep = m_StepCycle/2f;
m_Jumping = false;
m_AudioSource = GetComponent<AudioSource>();
m_MouseLook.Init(transform , m_Camera.transform);
}
// Update is called once per frame
private void Update()
{
RotateView();
// the jump state needs to read here to make sure it is not missed
if (!m_Jump)
{
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
{
StartCoroutine(m_JumpBob.DoBobCycle());
PlayLandingSound();
m_MoveDir.y = 0f;
m_Jumping = false;
}
if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
{
m_MoveDir.y = 0f;
}
m_PreviouslyGrounded = m_CharacterController.isGrounded;
}
private void PlayLandingSound()
{
m_AudioSource.clip = m_LandSound;
m_AudioSource.Play();
m_NextStep = m_StepCycle + .5f;
}
private void FixedUpdate()
{
float speed;
GetInput(out speed);
// always move along the camera forward as it is the direction that it being aimed at
Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;
// get a normal for the surface that is being touched to move along it
RaycastHit hitInfo;
Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
m_CharacterController.height/2f, Physics.AllLayers, QueryTriggerInteraction.Ignore);
desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
m_MoveDir.x = desiredMove.x*speed;
m_MoveDir.z = desiredMove.z*speed;
if (m_CharacterController.isGrounded)
{
m_MoveDir.y = -m_StickToGroundForce;
if (m_Jump)
{
m_MoveDir.y = m_JumpSpeed;
PlayJumpSound();
m_Jump = false;
m_Jumping = true;
}
}
else
{
m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
}
m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);
ProgressStepCycle(speed);
UpdateCameraPosition(speed);
m_MouseLook.UpdateCursorLock();
}
private void PlayJumpSound()
{
m_AudioSource.clip = m_JumpSound;
m_AudioSource.Play();
}
private void ProgressStepCycle(float speed)
{
if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
{
m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
Time.fixedDeltaTime;
}
if (!(m_StepCycle > m_NextStep))
{
return;
}
m_NextStep = m_StepCycle + m_StepInterval;
PlayFootStepAudio();
}
private void PlayFootStepAudio()
{
if (!m_CharacterController.isGrounded)
{
return;
}
if (tagAtual != "Untagged") {
for (int x = 0; x < SomDosPassos.Length; x++) {
if (tagAtual == SomDosPassos [x].tagchao) {
if (SomDosPassos [x].audios.Length > 1) {
int n = Random.Range (1, SomDosPassos [x].audios.Length);
m_AudioSource.clip = SomDosPassos [x].audios [n];
m_AudioSource.PlayOneShot (m_AudioSource.clip);
SomDosPassos [x].audios [n] = SomDosPassos [x].audios [0];
SomDosPassos [x].audios [0] = m_AudioSource.clip;
} else {
m_AudioSource.clip = SomDosPassos [x].audios [0];
m_AudioSource.PlayOneShot (m_AudioSource.clip);
}
break;
}
}
}
else {
if (SomPassosPadrao.Length > 1) {
int n = Random.Range (1, SomPassosPadrao.Length);
m_AudioSource.clip = SomPassosPadrao [n];
m_AudioSource.PlayOneShot (m_AudioSource.clip);
SomPassosPadrao [n] = SomPassosPadrao [0];
SomPassosPadrao [0] = m_AudioSource.clip;
} else {
m_AudioSource.clip = SomPassosPadrao[0];
m_AudioSource.PlayOneShot (m_AudioSource.clip);
}
}
}
private void UpdateCameraPosition(float speed)
{
Vector3 newCameraPosition;
if (!m_UseHeadBob)
{
return;
}
if (m_CharacterController.velocity.magnitude > 0 && m_CharacterController.isGrounded)
{
m_Camera.transform.localPosition =
m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude +
(speed*(m_IsWalking ? 1f : m_RunstepLenghten)));
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset();
}
else
{
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset();
}
m_Camera.transform.localPosition = newCameraPosition;
}
private void GetInput(out float speed)
{
// Read input
float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
float vertical = CrossPlatformInputManager.GetAxis("Vertical");
bool waswalking = m_IsWalking;
#if !MOBILE_INPUT
// On standalone builds, walk/run speed is modified by a key press.
// keep track of whether or not the character is walking or running
m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
#endif
// set the desired speed to be walking or running
speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
m_Input = new Vector2(horizontal, vertical);
// normalize input if it exceeds 1 in combined length:
if (m_Input.sqrMagnitude > 1)
{
m_Input.Normalize();
}
// handle speed change to give an fov kick
// only if the player is going to a run, is running and the fovkick is to be used
if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
{
StopAllCoroutines();
StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
}
}
private void RotateView()
{
m_MouseLook.LookRotation (transform, m_Camera.transform);
}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
tagAtual = hit.transform.tag;
Rigidbody body = hit.collider.attachedRigidbody;
//dont move the rigidbody if the character is on top of it
if (m_CollisionFlags == CollisionFlags.Below)
{
return;
}
if (body == null || body.isKinematic)
{
return;
}
body.AddForceAtPosition(m_CharacterController.velocity*0.1f, hit.point, ForceMode.Impulse);
}
}
}
Ambos os scripts são do First Person Controller da Unity, um tem um sistema de subir em escaca e o outro tem um sistema de som de passos pela tag do objeto. Gostaria de transformar esses scripts num só contendo todas as funções.
Re: Preciso de algúem para modificar um script, negociaremos o valor $
Opa, vi o tópico agora apenas.
Diga, por quê deseja unir ambos os sistemas em apenas 1 código? O "ideal" é ter códigos separados para funções separadas.
Diga, por quê deseja unir ambos os sistemas em apenas 1 código? O "ideal" é ter códigos separados para funções separadas.
Re: Preciso de algúem para modificar um script, negociaremos o valor $
Eu gostaria de unir para que as funções funcionassem em conjunto, os sons de passos de acordo com a tag do chão/piso e também o sistema de subir escadas, pois creio que fazer isso funcionar separadamente seria muito complicado.
Re: Preciso de algúem para modificar um script, negociaremos o valor $
Será que essa dinâmica de trocar o script do FPSController durante o gameplay poderia funcionar sem problemas? Ou eu poderia mudar o nome do script e pôr os dois ao mesmo tempo? Talvez isso causasse algum conflito, a não ser que ele fosse ativado no momento certo e logo em seguida desativado.

» Preciso de um script para simular a suspeçao a ar
» Preciso de um script para andar de moto alguem consegue me ajudar
» como modificar o script para receber e registar o dano no personagem
» [Ajuda] Preciso de ajuda para controlar e alterar o valor de Lerp de varios objetos
» Pessoal como posso modificar esses script para Joystick feito pelo Marcos Schultz
» Preciso de um script para andar de moto alguem consegue me ajudar
» como modificar o script para receber e registar o dano no personagem
» [Ajuda] Preciso de ajuda para controlar e alterar o valor de Lerp de varios objetos
» Pessoal como posso modificar esses script para Joystick feito pelo Marcos Schultz
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos