Entrar no carro com ThirdPerson [C#]
4 participantes
Página 1 de 1
Entrar no carro com ThirdPerson [C#]
Quero fazer um sistema para entrar no carro em C# com o meu player ThirdPerson(no caso eu tenho um asset chamado Invector TPC).
thiagotmi- Avançado
- PONTOS : 2638
REPUTAÇÃO : 14
Idade : 25
Áreas de atuação : Design, animação, programação básica.
Respeito as regras :
Re: Entrar no carro com ThirdPerson [C#]
Se tu quer é só começar então... Qual o problema? Dúvidas? Já começou a criar alguma coisa? Estamos aqui para ajudar a criar e tirar dúvidas, não para criarmos ou pesquisarmos a criação para ti! Abraços, sucesso velho!
Re: Entrar no carro com ThirdPerson [C#]
Opa eu esqueci de adicionar a duvida... É que eu tenho um asset de controle (se chama invector TPC) mas não consigo acoplar um script que o faça entrar no carro, ou um script sei lá que desative os scripts do Player e ative os scripts do Carro.recagonlei escreveu:Se tu quer é só começar então... Qual o problema? Dúvidas? Já começou a criar alguma coisa? Estamos aqui para ajudar a criar e tirar dúvidas, não para criarmos ou pesquisarmos a criação para ti! Abraços, sucesso velho!
thiagotmi- Avançado
- PONTOS : 2638
REPUTAÇÃO : 14
Idade : 25
Áreas de atuação : Design, animação, programação básica.
Respeito as regras :
Re: Entrar no carro com ThirdPerson [C#]
Entendi velho... Puts, ai fica complicado cara, pois é um assets de terceiros! Tu deveria pedir suporte para os criadores, que eles entendem melhor do asset e conseguem te ajudar. Mas como tu não consegue desativar os scripts do player? Cacheie todos eles em um outro script e passe uma função para desativa-los... Qual seria o erro?
Re: Entrar no carro com ThirdPerson [C#]
Mande uma foto dos scripts do player e outra dos scripts do carro para podermos te ajudar;
Phph09- Profissional
- PONTOS : 3788
REPUTAÇÃO : 240
Idade : 19
Respeito as regras :
Re: Entrar no carro com ThirdPerson [C#]
- Código:
using UnityEngine;
using System.Collections;
namespace Invector.CharacterController
{
[vClassHeader("Third Person Controller")]
public class vThirdPersonController : vThirdPersonAnimator
{
#region Variables
public static vThirdPersonController instance;
#endregion
protected virtual void Awake()
{
StartCoroutine(UpdateRaycast()); // limit raycasts calls for better performance
}
protected virtual void Start()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(this.gameObject);
this.gameObject.name = gameObject.name + " Instance";
}
else
{
Destroy(this.gameObject);
return;
}
#if !UNITY_EDITOR
Cursor.visible = false;
#endif
}
#region Locomotion Actions
public virtual void Sprint(bool value)
{
if(value)
{
if (currentStamina > 0 && input.sqrMagnitude > 0.1f)
{
if (isGrounded && !isCrouching)
isSprinting = !isSprinting;
}
}
else if (currentStamina <= 0 || input.sqrMagnitude < 0.1f || actions || isStrafing && !strafeWalkByDefault && (direction >= 0.5 || direction <= -0.5 || speed <= 0))
{
isSprinting = false;
}
}
public virtual void Crouch()
{
if (isGrounded && !actions)
{
if (isCrouching && CanExitCrouch())
isCrouching = false;
else
isCrouching = true;
}
}
public virtual void Strafe()
{
isStrafing = !isStrafing;
}
public virtual void Jump()
{
if (customAction) return;
// know if has enough stamina to make this action
bool staminaConditions = currentStamina > jumpStamina;
// conditions to do this action
bool jumpConditions = !isCrouching && isGrounded && !actions && staminaConditions && !isJumping;
// return if jumpCondigions is false
if (!jumpConditions) return;
// trigger jump behaviour
jumpCounter = jumpTimer;
isJumping = true;
// trigger jump animations
if (input.sqrMagnitude < 0.1f)
animator.CrossFadeInFixedTime("Jump", 0.1f);
else
animator.CrossFadeInFixedTime("JumpMove", .2f);
// reduce stamina
ReduceStamina(jumpStamina, false);
currentStaminaRecoveryDelay = 1f;
}
public virtual void Roll()
{
if (animator.IsInTransition(0)) return;
bool staminaCondition = currentStamina > rollStamina;
// can roll even if it's on a quickturn or quickstop animation
bool actionsRoll = !actions || (actions && (quickStop));
// general conditions to roll
bool rollConditions = (input != Vector2.zero || speed > 0.25f) && actionsRoll && isGrounded && staminaCondition && !isJumping;
if (!rollConditions || isRolling) return;
animator.SetTrigger("ResetState");
animator.CrossFadeInFixedTime("Roll", 0.1f);
ReduceStamina(rollStamina, false);
currentStaminaRecoveryDelay = 2f;
}
/// <summary>
/// Use another transform as reference to rotate
/// </summary>
/// <param name="referenceTransform"></param>
public virtual void RotateWithAnotherTransform(Transform referenceTransform)
{
var newRotation = new Vector3(transform.eulerAngles.x, referenceTransform.eulerAngles.y, transform.eulerAngles.z);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(newRotation), strafeRotationSpeed * Time.fixedDeltaTime);
targetRotation = transform.rotation;
}
#endregion
#region Check Action Triggers
/// <summary>
/// Call this in OnTriggerEnter or OnTriggerStay to check if enter in triggerActions
/// </summary>
/// <param name="other">collider trigger</param>
public virtual void CheckTriggers(Collider other)
{
try
{
CheckForAutoCrouch(other);
}
catch (UnityException e)
{
Debug.LogWarning(e.Message);
}
}
/// <summary>
/// Call this in OnTriggerExit to check if exit of triggerActions
/// </summary>
/// <param name="other"></param>
public virtual void CheckTriggerExit(Collider other)
{
AutoCrouchExit(other);
}
#region Update Raycasts
protected IEnumerator UpdateRaycast()
{
while (true)
{
yield return new WaitForEndOfFrame();
AutoCrouch();
StopMove();
}
}
#endregion
#region Crouch Methods
protected virtual void AutoCrouch()
{
if (autoCrouch)
isCrouching = true;
if (autoCrouch && !inCrouchArea && CanExitCrouch())
{
autoCrouch = false;
isCrouching = false;
}
}
protected virtual bool CanExitCrouch()
{
// radius of SphereCast
float radius = _capsuleCollider.radius * 0.9f;
// Position of SphereCast origin stating in base of capsule
Vector3 pos = transform.position + Vector3.up * ((colliderHeight * 0.5f) - colliderRadius);
// ray for SphereCast
Ray ray2 = new Ray(pos, Vector3.up);
// sphere cast around the base of capsule for check ground distance
if (Physics.SphereCast(ray2, radius, out groundHit, headDetect - (colliderRadius * 0.1f), autoCrouchLayer))
return false;
else
return true;
}
protected virtual void AutoCrouchExit(Collider other)
{
if (other.CompareTag("AutoCrouch"))
{
inCrouchArea = false;
}
}
protected virtual void CheckForAutoCrouch(Collider other)
{
if (other.gameObject.CompareTag("AutoCrouch"))
{
autoCrouch = true;
inCrouchArea = true;
}
}
#endregion
#endregion
}
}
Esse aqui é o controller do Player
thiagotmi- Avançado
- PONTOS : 2638
REPUTAÇÃO : 14
Idade : 25
Áreas de atuação : Design, animação, programação básica.
Respeito as regras :
Re: Entrar no carro com ThirdPerson [C#]
- Código:
//----------------------------------------------
// Realistic Car Controller
//
// Copyright 2015 BoneCracker Games
// http://www.bonecrackergames.com
//
//----------------------------------------------
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
[AddComponentMenu("BoneCracker Games/Realistic Car Controller/AI/AI Controller")]
public class RCC_AICarController : MonoBehaviour {
private RCC_CarControllerV3 carController;
private Rigidbody rigid;
// Waypoint Container.
private RCC_AIWaypointsContainer waypointsContainer;
public int currentWaypoint = 0;
// Raycast distances.
public LayerMask obstacleLayers = -1;
public int wideRayLength = 20;
public int tightRayLength = 20;
public int sideRayLength = 3;
private float rayInput = 0f;
private bool raycasting = false;
private float resetTime = 0f;
// Steer, motor, and brake inputs.
private float steerInput = 0f;
private float gasInput = 0f;
private float brakeInput = 0f;
public bool limitSpeed = false;
public float maximumSpeed = 100f;
public bool smoothedSteer = true;
// Brake Zone.
private float maximumSpeedInBrakeZone = 0f;
private bool inBrakeZone = false;
// Counts laps and how many waypoints passed.
public int lap = 0;
public int totalWaypointPassed = 0;
public int nextWaypointPassRadius = 40;
public bool ignoreWaypointNow = false;
// Unity's Navigator.
private UnityEngine.AI.NavMeshAgent navigator;
private GameObject navigatorObject;
void Awake() {
carController = GetComponent<RCC_CarControllerV3>();
rigid = GetComponent<Rigidbody>();
carController.AIController = true;
// carController.canEngineStall = false;
// carController.autoReverse = true;
waypointsContainer = FindObjectOfType(typeof(RCC_AIWaypointsContainer)) as RCC_AIWaypointsContainer;
navigatorObject = new GameObject("Navigator");
navigatorObject.transform.parent = transform;
navigatorObject.transform.localPosition = Vector3.zero;
navigatorObject.AddComponent<UnityEngine.AI.NavMeshAgent>();
navigatorObject.GetComponent<UnityEngine.AI.NavMeshAgent>().radius = 1;
navigatorObject.GetComponent<UnityEngine.AI.NavMeshAgent>().speed = 1f;
navigatorObject.GetComponent<UnityEngine.AI.NavMeshAgent>().height = 1;
navigatorObject.GetComponent<UnityEngine.AI.NavMeshAgent>().avoidancePriority = 99;
navigator = navigatorObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
}
void Update(){
navigator.transform.localPosition = new Vector3(0, carController.FrontLeftWheelCollider.transform.localPosition.y, carController.FrontLeftWheelCollider.transform.localPosition.z);
}
void FixedUpdate (){
if(!carController.canControl)
return;
Navigation();
FixedRaycasts();
ApplyTorques();
Resetting();
}
void Navigation (){
if(!waypointsContainer){
Debug.LogError("Waypoints Container Couldn't Found!");
enabled = false;
return;
}
if(waypointsContainer && waypointsContainer.waypoints.Count < 1){
Debug.LogError("Waypoints Container Doesn't Have Any Waypoints!");
enabled = false;
return;
}
// Next waypoint's position.
Vector3 nextWaypointPosition = transform.InverseTransformPoint( new Vector3(waypointsContainer.waypoints[currentWaypoint].position.x, transform.position.y, waypointsContainer.waypoints[currentWaypoint].position.z));
float navigatorInput = Mathf.Clamp(transform.InverseTransformDirection(navigator.desiredVelocity).x * 1.5f, -1f, 1f);
navigator.SetDestination(waypointsContainer.waypoints[currentWaypoint].position);
//Steering Input.
if(carController.direction == 1){
if(!ignoreWaypointNow)
steerInput = Mathf.Clamp((navigatorInput + rayInput), -1f, 1f);
else
steerInput = Mathf.Clamp(rayInput, -1f, 1f);
}else{
steerInput = Mathf.Clamp((-navigatorInput - rayInput), -1f, 1f);
}
if(!inBrakeZone){
if(carController.speed >= 25){
brakeInput = Mathf.Lerp(0f, .25f, (Mathf.Abs(steerInput)));
}else{
brakeInput = 0f;
}
}else{
brakeInput = Mathf.Lerp(0f, 1f, (carController.speed - maximumSpeedInBrakeZone) / maximumSpeedInBrakeZone);
}
if(!inBrakeZone){
if(carController.speed >= 10){
if(!carController.changingGear)
gasInput = Mathf.Clamp(1f - (Mathf.Abs(navigatorInput / 5f) - Mathf.Abs(rayInput / 5f)), .5f, 1f);
else
gasInput = 0f;
}else{
if(!carController.changingGear)
gasInput = 1f;
else
gasInput = 0f;
}
}else{
if(!carController.changingGear)
gasInput = Mathf.Lerp(1f, 0f, (carController.speed) / maximumSpeedInBrakeZone);
else
gasInput = 0f;
}
// Checks for the distance to next waypoint. If it is less than written value, then pass to next waypoint.
if (nextWaypointPosition.magnitude < nextWaypointPassRadius){
currentWaypoint ++;
totalWaypointPassed ++;
// If all waypoints are passed, sets the current waypoint to first waypoint and increase lap.
if (currentWaypoint >= waypointsContainer.waypoints.Count){
currentWaypoint = 0;
lap ++;
}
}
}
void Resetting (){
if(carController.speed <= 5 && transform.InverseTransformDirection(rigid.velocity).z < 1f)
resetTime += Time.deltaTime;
if(resetTime >= 4)
carController.direction = -1;
if(resetTime >= 6 || carController.speed >= 25){
carController.direction = 1;
resetTime = 0;
}
}
void FixedRaycasts(){
Vector3 forward = transform.TransformDirection ( new Vector3(0, 0, 1));
Vector3 pivotPos = new Vector3(transform.localPosition.x, carController.FrontLeftWheelCollider.transform.position.y, transform.localPosition.z);
RaycastHit hit;
// New bools effected by fixed raycasts.
bool tightTurn = false;
bool wideTurn = false;
bool sideTurn = false;
bool tightTurn1 = false;
bool wideTurn1 = false;
bool sideTurn1 = false;
// New input steers effected by fixed raycasts.
float newinputSteer1 = 0f;
float newinputSteer2 = 0f;
float newinputSteer3 = 0f;
float newinputSteer4 = 0f;
float newinputSteer5 = 0f;
float newinputSteer6 = 0f;
// Drawing Rays.
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(25, transform.up) * forward * wideRayLength, Color.white);
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(-25, transform.up) * forward * wideRayLength, Color.white);
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(7, transform.up) * forward * tightRayLength, Color.white);
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(-7, transform.up) * forward * tightRayLength, Color.white);
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(90, transform.up) * forward * sideRayLength, Color.white);
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(-90, transform.up) * forward * sideRayLength, Color.white);
// Wide Raycasts.
if (Physics.Raycast (pivotPos, Quaternion.AngleAxis(25, transform.up) * forward, out hit, wideRayLength, obstacleLayers) && !hit.collider.isTrigger && hit.transform.root != transform) {
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(25, transform.up) * forward * wideRayLength, Color.red);
newinputSteer1 = Mathf.Lerp (-.5f, 0f, (hit.distance / wideRayLength));
wideTurn = true;
}
else{
newinputSteer1 = 0f;
wideTurn = false;
}
if (Physics.Raycast (pivotPos, Quaternion.AngleAxis(-25, transform.up) * forward, out hit, wideRayLength, obstacleLayers) && !hit.collider.isTrigger && hit.transform.root != transform) {
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(-25, transform.up) * forward * wideRayLength, Color.red);
newinputSteer4 = Mathf.Lerp (.5f, 0f, (hit.distance / wideRayLength));
wideTurn1 = true;
}else{
newinputSteer4 = 0f;
wideTurn1 = false;
}
// Tight Raycasts.
if (Physics.Raycast (pivotPos, Quaternion.AngleAxis(7, transform.up) * forward, out hit, tightRayLength, obstacleLayers) && !hit.collider.isTrigger && hit.transform.root != transform) {
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(7, transform.up) * forward * tightRayLength , Color.red);
newinputSteer3 = Mathf.Lerp (-1f, 0f, (hit.distance / tightRayLength));
tightTurn = true;
}else{
newinputSteer3 = 0f;
tightTurn = false;
}
if (Physics.Raycast (pivotPos, Quaternion.AngleAxis(-7, transform.up) * forward, out hit, tightRayLength, obstacleLayers) && !hit.collider.isTrigger && hit.transform.root != transform) {
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(-7, transform.up) * forward * tightRayLength, Color.red);
newinputSteer2 = Mathf.Lerp (1f, 0f, (hit.distance / tightRayLength));
tightTurn1 = true;
}else{
newinputSteer2 = 0f;
tightTurn1 = false;
}
// Side Raycasts.
if (Physics.Raycast (pivotPos, Quaternion.AngleAxis(90, transform.up) * forward, out hit, sideRayLength, obstacleLayers) && !hit.collider.isTrigger && hit.transform.root != transform) {
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(90, transform.up) * forward * sideRayLength , Color.red);
newinputSteer5 = Mathf.Lerp (-1f, 0f, (hit.distance / sideRayLength));
sideTurn = true;
}else{
newinputSteer5 = 0f;
sideTurn = false;
}
if (Physics.Raycast (pivotPos, Quaternion.AngleAxis(-90, transform.up) * forward, out hit, sideRayLength, obstacleLayers) && !hit.collider.isTrigger && hit.transform.root != transform) {
Debug.DrawRay (pivotPos, Quaternion.AngleAxis(-90, transform.up) * forward * sideRayLength, Color.red);
newinputSteer6 = Mathf.Lerp (1f, 0f, (hit.distance / sideRayLength));
sideTurn1 = true;
}else{
newinputSteer6 = 0f;
sideTurn1 = false;
}
if(wideTurn || wideTurn1 || tightTurn || tightTurn1 || sideTurn || sideTurn1)
raycasting = true;
else
raycasting = false;
if(raycasting)
rayInput = (newinputSteer1 + newinputSteer2 + newinputSteer3 + newinputSteer4 + newinputSteer5 + newinputSteer6);
else
rayInput = 0f;
if(raycasting && Mathf.Abs(rayInput) > .5f)
ignoreWaypointNow = true;
else
ignoreWaypointNow = false;
}
void ApplyTorques(){
if(carController.direction == 1){
if(!limitSpeed){
carController.gasInput = gasInput;
}else{
carController.gasInput = gasInput * Mathf.Clamp01(Mathf.Lerp(10f, 0f, (carController.speed) / maximumSpeed));
}
}else{
carController.gasInput = 0f;
}
if(smoothedSteer)
carController.steerInput = Mathf.Lerp(carController.steerInput, steerInput, Time.deltaTime * 20f);
else
carController.steerInput = steerInput;
if(carController.direction == 1)
carController.brakeInput = brakeInput;
else
carController.brakeInput = gasInput;
}
void OnTriggerEnter (Collider col){
if(col.gameObject.GetComponent<RCC_AIBrakeZone>()){
inBrakeZone = true;
maximumSpeedInBrakeZone = col.gameObject.GetComponent<RCC_AIBrakeZone>().targetSpeed;
}
}
void OnTriggerExit (Collider col){
if(col.gameObject.GetComponent<RCC_AIBrakeZone>()){
inBrakeZone = false;
maximumSpeedInBrakeZone = 0;
}
}
}
E esse é do Carro
thiagotmi- Avançado
- PONTOS : 2638
REPUTAÇÃO : 14
Idade : 25
Áreas de atuação : Design, animação, programação básica.
Respeito as regras :
Re: Entrar no carro com ThirdPerson [C#]
Esses sistemas possuem suporte através dos desenvolvedores, e tenho certeza que se pedir eles vão ajudar você :D aqui é o lugar errado para pedir isso!
Madness- Designer
- PONTOS : 3609
REPUTAÇÃO : 222
Áreas de atuação : Designer
Iniciante C++
Quase um programador C#
Respeito as regras :
Re: Entrar no carro com ThirdPerson [C#]
Madness escreveu:Esses sistemas possuem suporte através dos desenvolvedores, e tenho certeza que se pedir eles vão ajudar você :D aqui é o lugar errado para pedir isso!
Ok! Obrigado!
thiagotmi- Avançado
- PONTOS : 2638
REPUTAÇÃO : 14
Idade : 25
Áreas de atuação : Design, animação, programação básica.
Respeito as regras :
Tópicos semelhantes
» Personagem Entrar No Carro (Com Primeira Pessoa Sem Animaçao De Entrar Em C#)
» Entrar e sair do carro
» Entrar no carro (Com Anim)
» Como Entrar no Carro (RCC)
» [TUTORIAL] Entrar no carro estilo GTA
» Entrar e sair do carro
» Entrar no carro (Com Anim)
» Como Entrar no Carro (RCC)
» [TUTORIAL] Entrar no carro estilo GTA
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos