Can someone help me with a script to move my game object relative to the camera’s direction, for instance, if I was using the Mouse Orbit script? I really don’t want to work with the Third Person Script of the Platformer script. I’d rather be a rebel and go custom.
Anything?
BUMP
Sure, just use transform.Translate(camera.forward), that’ll push it in the cameras direction.
Thanks, but I just figured out that problem before you answered. But I’m facing another problem with rotating the object towards the direction it’s moving, and what can I put in the In Air Controls to control the object in air?
#pragma strict
#pragma implicit
#pragma downcast
//OUTSIDE SCRIPT VARIABLES
var canMove = true;
var moveSpeed : float = 4.0;
var rotateSpeed : float = 5.0;
var canJump = true;
var jumpHeight : float = 12.0;
var gravity : float = 30.0;
var canDoubleJump = true;
var doubleHeight : float = 4.0;
var padHeight : float = 25.0;
private var moveDirection = Vector3.zero;
function Update(){
var controller : CharacterController = GetComponent(CharacterController);
//CONTROLS THE MOVEMENT
if(controller.isGrounded canMove)
{
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = Camera.main.transform.TransformDirection(moveDirection);
moveDirection *= moveSpeed;
canDoubleJump = true;
//CONTROLS THE JUMP
if(Input.GetButtonDown("Jump") canJump)
{
moveDirection.y = jumpHeight;
}
}
//CONTROLS MOVEMENT IN AIR
if(!controller.isGrounded canMove)
{
}
//CONTROLS DOUBLE JUMPING
if(!controller.isGrounded canDoubleJump canJump Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpHeight + doubleHeight;
canDoubleJump = false;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function OnTriggerStay(other : Collider){
//MOVING ON PLATFORMS
if(other.tag == "Platform"){
this.transform.parent = other.transform.parent;
}
}
function OnTriggerEnter(other : Collider){
if(other.tag == "Jump Pad"){
moveDirection.y = padHeight;
}
}
function OnTriggerExit(other : Collider){
//MOVING OFF PLATFORMS
if(other.tag == "Platform"){
this.transform.parent = null;
}
}
@script RequireComponent(CharacterController);