I am working on making the character do a sort of run up the wall when the player holds the left control button. I can get the character to move up, but there are a few issues.
Firstly, it is quite jumpy when moving, is this simply because of the force being added? Or is it due to lag?
Secondly, when the player lets go of the left control button, the character immediately drops to the ground rather than staying in the air and falling as though it just jumped. Why is this?
Sample code below:
var walkHeight : Vector3;
var wallJumpSensorLength : float = 5;
var wallSteps : float = 0;
var wallMaxSteps : float = 5;
var thisObj : GameObject;
function Start () {
}
function FixedUpdate () {
WallJump(); }
function Walk () {
}
function WallJump () {
var pos : Vector3; var hit : RaycastHit;
walkHeight = Vector3(0, 10, 0); pos = transform.position;
if (Physics.Raycast(pos, transform.forward, hit, wallJumpSensorLength)) {
Debug.DrawLine(pos, hit.point, Color.red); Debug.Log("Wall Infront");
if (Input.GetKey(KeyCode.LeftControl)) {
for (var i = 0; i < wallMaxSteps; i++){
Debug.Log("WallJump");
thisObj.rigidbody.isKinematic = false;
thisObj.rigidbody.AddForce(walkHeight);
wallSteps = wallSteps + 1; } } else {
thisObj.rigidbody.isKinematic = true;
wallSteps = 0; } } else {
} }
Thanks in advance to any replies.
~MGMaddMann
↧