Hi Everybody,
When my Character Controller Jumps and goes down to Ground and touches it, I want it to bounce once. I’m using PlayerRelativeControl.js but really don’t know what to customize. Here is my script.
//////////////////////////////////////////////////////////////
function Update()
{
var movement = thisTransform.TransformDirection( Vector3( moveJoystick.position.x, 0, 0) );
// We only want horizontal movement
movement.y = 0;
movement.Normalize();
var cameraTarget = Vector3.zero;
// Apply movement from move joystick
var absJoyPos = Vector2( Mathf.Abs( moveJoystick.position.x ), Mathf.Abs( moveJoystick.position.y ) );
if ( absJoyPos.y > absJoyPos.x )
{
if ( moveJoystick.position.y > 0 )
movement *= forwardSpeed * absJoyPos.y;
else
{
movement *= backwardSpeed * absJoyPos.y;
cameraTarget.z = moveJoystick.position.y * 0.75;
}
}
else
{
movement *= sidestepSpeed * absJoyPos.x;
// Let's move the camera a bit, so the character isn't stuck under our thumb
cameraTarget.x = -moveJoystick.position.x * 0.5;
}
// Check for jump
if ( character.isGrounded )
{
if ( rotateJoystick.tapCount == 1 )
{
// Apply the current movement to launch velocity
velocity = character.velocity;
velocity.y = jumpSpeed;
audio.PlayOneShot(jumpSoundClip, 0.7);
}
}
else
{
// Apply gravity to our velocity to diminish it over time
velocity.y += Physics.gravity.y * Time.deltaTime;
//Debug.Log(velocity.y);
// Move the camera back from the character when we jump
cameraTarget.z = -jumpSpeed * 0.25;
// Adjust additional movement while in-air
//movement.x *= inAirMultiplier;
//movement.z *= inAirMultiplier;
}
movement += velocity;
movement += Physics.gravity;
movement *= Time.deltaTime;
// Actually move the character
character.Move( movement );
if ( character.isGrounded ){
// Remove any persistent velocity after landing
velocity = Vector3.zero;
}
// Seek camera towards target position
var pos = cameraPivot.localPosition;
pos.x = Mathf.SmoothDamp( pos.x, cameraTarget.x, cameraVelocity.x, 0.3 );
pos.z = Mathf.SmoothDamp( pos.z, cameraTarget.z, cameraVelocity.z, 0.5 );
cameraPivot.localPosition = pos;
// Apply rotation from rotation joystick
if ( character.isGrounded )
{
var camRotation = rotateJoystick.position;
camRotation.x *= rotationSpeed.x;
camRotation.y *= rotationSpeed.y;
camRotation *= Time.deltaTime;
// Rotate the character around world-y using x-axis of joystick
thisTransform.Rotate( 0, camRotation.x, 0, Space.World );
// Rotate only the camera with y-axis input
cameraPivot.Rotate( camRotation.y, 0, 0 );
}
}
Can you guys please help me out so I can be out of it?
Thank you!