- Home /
Problem is not reproducible or outdated -- OP is asking a new nice questions
transform.position over time? & mouselook rotate player?
I am trying to make parkour in my game, I have made raycasts and everything to make it work. But I have run into a few problems. Firstly, how do I make transform.position move over time? And secondly, how do I make the Mouselook rotate the player? Because the move direction is dependent on the rotation of the Z co-ordinate on the player variable?
(UnityScript for Parkour & C# for MouseLook (Unity's prefab mouselook))
Parkour Script
var Player : GameObject;
var Arms : GameObject;
var SkyTrigger : GameObject;
var HeadTrigger : GameObject;
var WaistTrigger : GameObject;
var VaultHeight : float = 1;
var VaultLength : float = 2;
var ClimbHeight : float = 2;
var ClimbLength : float = 0.5;
private var SkyBoole : boolean = false;
private var HeadBoole : boolean = false;
private var WaistBoole : boolean = false;
private var ClimbEnabled : boolean = true;
private var VaultEnabled : boolean = true;
function Start()
{
Arms.animation.wrapMode = WrapMode.Loop;
Arms.animation.Play("Idle");
}
function Update()
{
var SkyRay : RaycastHit;
var HeadRay : RaycastHit;
var WaistRay : RaycastHit;
if(Physics.Raycast(SkyTrigger.transform.position, SkyTrigger.transform.forward, SkyRay, 1))
{
SkyBoole = true;
}
if(Physics.Raycast(HeadTrigger.transform.position, HeadTrigger.transform.forward, HeadRay, 0.25))
{
HeadBoole = true;
}
if(Physics.Raycast(WaistTrigger.transform.position, WaistTrigger.transform.forward, WaistRay, 0.25))
{
WaistBoole = true;
}
if(VaultEnabled)
{
if(WaistBoole && !HeadBoole)
{
ClimbEnabled = false;
VaultEnabled = false;
WaistBoole = false;
HeadBoole = false;
SkyBoole = false;
Vault();
}
}
if(ClimbEnabled)
{
if(WaistBoole && HeadBoole && !SkyBoole)
{
ClimbEnabled = false;
VaultEnabled = false;
WaistBoole = false;
HeadBoole = false;
SkyBoole = false;
Climb();
}
}
}
function Vault()
{
Arms.animation.wrapMode = WrapMode.Once;
ClimbEnabled = false;
VaultEnabled = false;
Arms.animation.CrossFade("Vault");
yield WaitForSeconds (0.5);
Player.transform.position.y=transform.position.y+VaultHeight;
Player.transform.localPosition.z=transform.localPosition.z+VaultLength;
yield WaitForSeconds (1);
Arms.animation.CrossFade("Idle");
Arms.animation.wrapMode = WrapMode.Loop;
ClimbEnabled = true;
VaultEnabled = true;
WaistBoole = false;
HeadBoole = false;
SkyBoole = false;
}
function Climb()
{
Arms.animation.wrapMode = WrapMode.Once;
ClimbEnabled = false;
VaultEnabled = false;
Arms.animation.CrossFade("Climb");
yield WaitForSeconds (1.35);
Player.transform.position.y=transform.position.y+ClimbHeight;
Player.transform.localPosition.z=transform.localPosition.z+ClimbLength;
yield WaitForSeconds (1);
Arms.animation.CrossFade("Idle");
Arms.animation.wrapMode = WrapMode.Loop;
ClimbEnabled = true;
VaultEnabled = true;
WaistBoole = false;
HeadBoole = false;
SkyBoole = false;
}
And MouseLook is Unity's Default Prefab
Is your player a rigidbody, has a character controller or none of them both?
Also if the $$anonymous$$ouseLook Script really is just the standard script you can remove it from your question. $$anonymous$$akes it easier to read.
$$anonymous$$y character has a Character Controller on it. & thanks for responding :)
Then you can use CharacterController.$$anonymous$$ove ( http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.$$anonymous$$ove.html )
Thanks, But how do i make it move up first with this mechanic?
And how do I make it move a specific distance in the forward direction, ins$$anonymous$$d of the way it works right now?