This commit is contained in:
Benjamín 2021-07-22 13:44:50 +02:00
commit f7ffc60a1d
5 changed files with 24 additions and 57 deletions

@ -6283,7 +6283,7 @@ Camera:
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 13.65243
orthographic size: 14
m_Depth: -1
m_CullingMask:
serializedVersion: 2
@ -6768,7 +6768,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 737155566}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 176, y: 14.4, z: 92.19983}
m_LocalPosition: {x: 143.4, y: 14.4, z: 92.19983}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 998253299}
@ -6819,7 +6819,7 @@ SpriteRenderer:
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 2
m_Size: {x: 320, y: 400}
m_Size: {x: 400, y: 500}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
@ -22475,7 +22475,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1232501489}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 179, y: -23, z: 2.1998286}
m_LocalPosition: {x: 156, y: 45, z: 2.1998286}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 998253299}

@ -264,18 +264,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8057fdb619b42d94390909e7bc867d87, type: 3}
m_Name:
m_EditorClassIdentifier:
m_JumpForce: 500
m_JumpForce: 20
SFX: {fileID: 517709047}
JumpSFX: {fileID: 8300000, guid: 437cbeaabc4a81e4e917fb190ecc096c, type: 3}
m_MovementSmoothing: 0.05
m_AirControl: 1
m_WhatIsGround:
serializedVersion: 2
m_Bits: 8
m_GroundCheck: {fileID: 1909349660}
OnLandEvent:
m_PersistentCalls:
m_Calls: []
--- !u!114 &4766649
MonoBehaviour:
m_ObjectHideFlags: 0

@ -7,11 +7,8 @@ public class CharacterController2D : MonoBehaviour
public AudioSource SFX;
public AudioClip JumpSFX;
[Range(0, .3f)] [SerializeField] private float m_MovementSmoothing = .05f; // How much to smooth out the movement
[SerializeField] private bool m_AirControl = false; // Whether or not a player can steer while jumping;
[SerializeField] private LayerMask m_WhatIsGround; // A mask determining what is ground to the character
[SerializeField] private Transform m_GroundCheck; // A position marking where to check if the player is grounded.
public LayerMask m_WhatIsGround; // A mask determining what is ground to the character
public Transform m_GroundCheck; // A position marking where to check if the player is grounded.
const float k_GroundedRadius = .2f; // Radius of the overlap circle to determine if grounded
private bool m_Grounded; // Whether or not the player is grounded.
@ -20,25 +17,14 @@ public class CharacterController2D : MonoBehaviour
private bool m_FacingRight = true; // For determining which way the player is currently facing.
private Vector3 m_Velocity = Vector3.zero;
[Header("Events")]
[Space]
public UnityEvent OnLandEvent;
[System.Serializable]
public class BoolEvent : UnityEvent<bool> { }
private void Awake()
{
m_Rigidbody2D = GetComponent<Rigidbody2D>();
if (OnLandEvent == null)
OnLandEvent = new UnityEvent();
}
private void FixedUpdate()
{
bool wasGrounded = m_Grounded;
m_Grounded = false;
// The player is grounded if a circlecast to the groundcheck position hits anything designated as ground
@ -49,44 +35,27 @@ public class CharacterController2D : MonoBehaviour
if (colliders[i].gameObject != gameObject)
{
m_Grounded = true;
if (!wasGrounded)
OnLandEvent.Invoke();
}
}
}
public void Move(float move, bool jump)
{
//only control the player if grounded or airControl is turned on
if (m_Grounded || m_AirControl)
{
// Move the character by finding the target velocity
Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y);
// And then smoothing it out and applying it to the character
m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);
// If the input is moving the player right and the player is facing left...
if (move > 0 && !m_FacingRight)
{
// ... flip the player.
//Flip();
}
// Otherwise if the input is moving the player left and the player is facing right...
else if (move < 0 && m_FacingRight)
{
// ... flip the player.
//Flip();
}
}
Vector3 targetVelocity = m_Rigidbody2D.velocity;
targetVelocity[0] = move * 10f;
m_Rigidbody2D.velocity = targetVelocity;
// If the player should jump...
if (m_Grounded && jump)
{
// Add a vertical force to the player.
m_Grounded = false;
m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
targetVelocity = m_Rigidbody2D.velocity;
targetVelocity[1] = m_JumpForce;
m_Rigidbody2D.velocity = targetVelocity;
SFX.clip = JumpSFX;
SFX.Play();
}

@ -35,12 +35,12 @@ public class PlayerControls : MonoBehaviour
if (switchy){
sprite.flipY = true;
rb.sharedMaterial = top;
controller.m_JumpForce = controller.m_JumpForce * 1.6f;
controller.m_JumpForce = controller.m_JumpForce * 2f;
}
else {
sprite.flipY = false;
rb.sharedMaterial = bottom;
controller.m_JumpForce = controller.m_JumpForce / 1.6f;
controller.m_JumpForce = controller.m_JumpForce / 2f;
}
sfx.clip = RotateSFX;
sfx.Play();

@ -9,24 +9,27 @@ EditorUserSettings:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0
RecentlyUsedScenePath-1:
value: 22424703114646680e0b0227036c73150012147f623d28393930
value: 22424703114646680e0b0227036c731500121478623d28393930
flags: 0
RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c7919181e0b22623d28393930
flags: 0
RecentlyUsedScenePath-3:
value: 22424703114646680e0b0227036c73150012147b623d28393930
flags: 0
RecentlyUsedScenePath-4:
value: 22424703114646680e0b0227036c731500121479623d28393930
flags: 0
RecentlyUsedScenePath-4:
value: 22424703114646680e0b0227036c73150012147c623d28393930
flags: 0
RecentlyUsedScenePath-5:
value: 22424703114646680e0b0227036c731500121478623d28393930
value: 22424703114646680e0b0227036c73150012147f623d28393930
flags: 0
RecentlyUsedScenePath-6:
value: 22424703114646680e0b0227036c73150012147e623d28393930
flags: 0
RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c73150012147b623d28393930
flags: 0
RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c6b0502180a232d2468252320092a
flags: 0
UnityRemoteCompression: