- Home /
How to have player “slide” on pipes and rails?
Hello , i need to create a skid or slips effect. I want create the skid or slips effect as in sunset overdrive : http://www.goodgamebro.com/omega/wp-content/uploads/2014/06/sunset-overdrive-e3-rollercoaster-1.jpg , when the main character slips on the electrical cables and on the rails. how can I create the same result? in C#. See this video: https://www.youtube.com/watch?v=zXjNkoQQPls (from 1.20 min to 1.25) . I have create this code: -OnTrigger- (apply to electric cables)
using UnityEngine;
using System.Collections;
public class OnTriggerEnterScroll : MonoBehaviour {
/*ISTRUZIONI : Inserire questo Script all'interno dell'Elemento che entra in contatto con il Trigger */
public Transform target; // Player
AutoMove AutoMoveScript; // richiamo variabili Script AutoMove
// Use this for initialization
void Start () {
AutoMoveScript = target.GetComponent<AutoMove>(); // Richiano componente AutoMove
}
// Update is called once per frame
void Update () {
Vector3 targetDir = target.position - transform.position;
Debug.Log(targetDir);
}
void OnTriggerEnter(Collider other) { // Quando il player entra nel Trigger
if(other.collider.name == "MainCharacter"){
AutoMoveScript.MoveSpeed = 8; // Cambio variabile di Velocita'
AutoMoveScript.activeAutoMoveW = true; // Cambio variabile di scorrimento
AutoMoveScript.activeAutoMoveS = false; // Cambio variabile di scorrimento
}
}
void OnTriggerStay(Collider other) { // Quando il player e' nel Trigger
if(other.collider.name == "MainCharacter"){
if(Input.GetKey(KeyCode.W)){
AutoMoveScript.activeAutoMoveW = true; // Cambio variabile di scorrimento
AutoMoveScript.activeAutoMoveS = false; // Cambio variabile di scorrimento
}
if(Input.GetKey(KeyCode.S)){
AutoMoveScript.activeAutoMoveS = true; // Cambio variabile di scorrimento
AutoMoveScript.activeAutoMoveW = false; // Cambio variabile di scorrimento
}
}
}
void OnTriggerExit(Collider other) { // Quando il player esce nel Trigger
if(other.collider.name == "MainCharacter"){
AutoMoveScript.MoveSpeed = 8; // Cambio variabile di Velocita'
AutoMoveScript.activeAutoMoveS = false; // Cambio variabile di scorrimento
AutoMoveScript.activeAutoMoveW = false; // Cambio variabile di scorrimento
}
}
}
-AutoMove- (apply on main Character)
using UnityEngine;
using System.Collections;
public class AutoMove : MonoBehaviour {
/*ISTRUZIONI : Inserire questo Script all'interno del Player */
public bool activeAutoMoveW = false; //variabile controllo Forward
public bool activeAutoMoveS = false; //variabile controllo Back
public int MoveSpeed = 8; //variabile velocità di scorrimento
public bool activeSelect = false; //variabile controllo Select
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(activeAutoMoveW == true)
{
transform.Translate(Vector3.forward * MoveSpeed * Time.fixedDeltaTime, Space.World); // Scorrimento in avari
}
if(activeAutoMoveS == true)
{
transform.Translate(Vector3.back * MoveSpeed * Time.fixedDeltaTime, Space.World); // Scorrimento in dietro
}
if(Input.GetKeyDown(KeyCode.Q) && activeSelect == false)
{
MoveSpeed = 1; // Cambio variabile di scorrimento
activeSelect = true; // Cambio variabile Slect
}else if(Input.GetKeyDown(KeyCode.Q) && activeSelect == true)
{
MoveSpeed = 8; // Cambio variabile di scorrimento
activeSelect = false; // Cambio variabile Slect
}
}
}
The system create the slips effect but don't understand what is the direction of the character.
This is the alternative code , but doesn't work.
public class Auto$$anonymous$$ove : $$anonymous$$onoBehaviour { public Vector3[] points; private int currentIndex = -1; ...
void Update() { if(activeAuto$$anonymous$$oveW == true) { Vector3 direction = points[i+1]-points[i]; transform.position += direction $$anonymous$$oveSpeed Time.fixedDeltaTime;
if((transform.position - points[i+1]).sqr$$anonymous$$agnitude < 0.1f)
//check if we are at the next point currentIndex++; } if(activeAuto$$anonymous$$oveS == true) { Vector3 direction = points[i+1]-points[i]; transform.position -= direction $$anonymous$$oveSpeed Time.fixedDeltaTime;
if((transform.position - points[i]).sqr$$anonymous$$agnitude < 0.1f)
//check if we are at the next point currentIndex--; }
if(currentIndex < 0 || currentIndex > points.Length) //check
if we are at either edge of the line and then end the slip { activeAuto$$anonymous$$oveW = false; activeAuto$$anonymous$$oveS = false; {
... }
public void BeginSlip(Vector3[] points) //called from the object when you want to begin the slip { this.points = points; //get the slip points from the object you slip on
//find the closest point
float $$anonymous$$Dist = float.$$anonymous$$axValue;
for(int i=0; i {
float currentDist = (transform.position -
points[i]).sqr$$anonymous$$agnitude; if(currentDist < $$anonymous$$Dist) { $$anonymous$$Dist = currentDist; currentIndex = i; } } } }
Your answer
Follow this Question
Related Questions
What is the Unit of "Slip" in the Wheel Collider? 3 Answers
How to make Physics2D more "stable" 0 Answers
Decreasing wheel friction with velocity 1 Answer
Simple arcade car Physics 0 Answers
enabling trail renderer 1 Answer