- Home /
Question by
graham1989 · Oct 22, 2013 at 11:02 AM ·
vector3platformertranslate
Vector 3 help?
Ok I am making a platformer, similar to original tomb raider games, I have almost got my script done to make my character climb up the ledges but struggling to find the best way to do this.
Here is my script, at the moment when I press up when grabbing the character moves forward and up, I just need a way to stop the character when he moves up and forward the right distance to get up on the ledge. There is probably a really simple solution to this but just cant seem to think of what to do. Thanks for any help. (PS sorry if my script is messy im fairly new).
var hit : RaycastHit;
var player1 : GameObject;
var cam1 : GameObject;
var cam2 : GameObject;
var guysGrabbin : boolean = false;
var GrabHeight = 1.0;
var upPressed : boolean = false;
var startPos = new Vector3();
var guysUp = false;
var timer : float = 3;
function Start ()
{
}
function Update ()
{
if(Physics.Raycast(transform.position, transform.forward, hit, 2))
{
print(hit.collider.tag);
Debug.DrawLine(transform.position, hit.collider.transform.position, Color.red);
}
startPos = player1.transform.position;
Debug.Log(Time);
if(upPressed == true)
{
player1.transform.Translate(Vector3.up * Time.deltaTime * 4);
player1.transform.Translate(Vector3.forward * Time.deltaTime * 2);
}
if(guysUp == true)
{
guysGrabbin = false;
player1.GetComponent(CharacterMotor).enabled = true;
player1.GetComponent(MouseLook).enabled = true;
AnimationScript.StopAnimation = false;
cam1.active = true;
cam2.active = false;
upPressed = false;
}
GrabHeight = hit.collider.transform.position.y - 2.47;
if(upPressed == false)
{
if(hit.collider.tag == "GuyReached")
{
guysGrabbin = true;
player1.GetComponent(CharacterMotor).enabled = false;
player1.GetComponent(MouseLook).enabled = false;
player1.transform.position.y = GrabHeight;
AnimationScript.StopAnimation = true;
cam1.active = false;
cam2.active = true;
}
}
if(guysGrabbin == true)
{
if(Input.GetKeyUp(KeyCode.UpArrow))
{
guysGrabbin = false;
upPressed = true;
player1.GetComponent(CharacterMotor).enabled = false;
player1.GetComponent(MouseLook).enabled = false;
AnimationScript.StopAnimation = false;
cam1.active = true;
cam2.active = false;
}
}
if(guysGrabbin == true)
{
if(Input.GetKeyUp(KeyCode.DownArrow))
{
guysGrabbin = false;
player1.GetComponent(CharacterMotor).enabled = true;
player1.GetComponent(MouseLook).enabled = true;
AnimationScript.StopAnimation = false;
cam1.active = true;
cam2.active = false;
}
}
}
Comment