Commit 48177f4b authored by 16도재형's avatar 16도재형

플레이어 이동, 점프, 2단점프 구현

parent e31aa0af
fileFormatVersion: 2
guid: 2b9d727852d39d04c9aa30a975e25aea
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!62 &6200000
PhysicsMaterial2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: slippery
friction: 0
bounciness: 0
fileFormatVersion: 2
guid: 75bcbc84e3971cc4da003035c7183a62
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 6200000
userData:
assetBundleName:
assetBundleVariant:
......@@ -21,7 +21,10 @@ GameObject:
- component: {fileID: 4861876781168000}
- component: {fileID: 8195094281964402364}
- component: {fileID: 3664157346213556122}
m_Layer: 0
- component: {fileID: 50808621241149756}
- component: {fileID: 66289433936503254}
- component: {fileID: 2113883504774285740}
m_Layer: 8
m_Name: Room0
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -41,6 +44,85 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &50808621241149756
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1306971874785268}
m_BodyType: 2
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!66 &66289433936503254
CompositeCollider2D:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1306971874785268}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_GeometryType: 0
m_GenerationType: 0
m_EdgeRadius: 0
m_ColliderPaths:
- m_Collider: {fileID: 2113883504774285740}
m_ColliderPaths:
- - X: 240000000
Y: 120000000
- X: 0
Y: 120000000
- X: 0
Y: 0
- X: 240000000
Y: 0
- - X: 10000000
Y: 10000000
- X: 10000000
Y: 110000000
- X: 230000000
Y: 110000000
- X: 230000000
Y: 10000000
m_CompositePaths:
m_Paths:
- - {x: 24, y: 12}
- {x: 0, y: 12}
- {x: 0, y: 0}
- {x: 24, y: 0}
- - {x: 1, y: 1}
- {x: 1, y: 11}
- {x: 23, y: 11}
- {x: 23, y: 1}
m_VertexDistance: 0.0005
--- !u!19719996 &2113883504774285740
TilemapCollider2D:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1306971874785268}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 1
m_Offset: {x: 0, y: 0}
--- !u!483693784 &3664157346213556122
TilemapRenderer:
m_ObjectHideFlags: 1
......
......@@ -299,6 +299,7 @@ GameObject:
- component: {fileID: 489222436}
- component: {fileID: 489222435}
- component: {fileID: 489222434}
- component: {fileID: 489222438}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
......@@ -320,11 +321,11 @@ Rigidbody2D:
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_GravityScale: 2
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_CollisionDetection: 1
m_Constraints: 4
--- !u!114 &489222435
MonoBehaviour:
......@@ -337,10 +338,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f289cad4933d4bf42ae5c82c57bd88e4, type: 3}
m_Name:
m_EditorClassIdentifier:
speed: 0
maxSpeed: 0
jumpSpeed: 0
doubleJumpSpeed: 0
speed: 300
jumpSpeed: 10
doubleJumpSpeed: 10
groundLayer:
serializedVersion: 2
m_Bits: 256
rayDistance: 1
--- !u!212 &489222436
SpriteRenderer:
m_ObjectHideFlags: 0
......@@ -394,12 +398,37 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 489222433}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2, y: 1, z: 0}
m_LocalPosition: {x: 2, y: 1.8, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &489222438
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 489222433}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: -0.1}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 0.78125, y: 1.5625}
newSize: {x: 0.78125, y: 1.5625}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.7, y: 1.4}
m_EdgeRadius: 0
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0
......@@ -471,7 +500,7 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalPosition: {x: 6.08, y: 3.21, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
......@@ -829,6 +858,11 @@ Prefab:
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 66289433936503254, guid: 279f5b34ed5c53545990e499c74cbbe7,
type: 2}
propertyPath: m_Material
value:
objectReference: {fileID: 6200000, guid: 75bcbc84e3971cc4da003035c7183a62, type: 2}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 279f5b34ed5c53545990e499c74cbbe7, type: 2}
m_IsPrefabAsset: 0
......
......@@ -3,19 +3,29 @@ using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
private Rigidbody2D rb; // RigidBody2D of this game object
// Speeds of player
[SerializeField]
private float dx; // Variation of horizontal speed
[SerializeField]
private float maxSpeed;
private float speed;
[SerializeField]
private float jumpSpeed;
[SerializeField]
private float doubleJumpSpeed;
private bool isGround = true; // Is the player on the ground?
private bool isDoubleJumping = false; // Is the player double jumping?
private Rigidbody2D rb; // RigidBody2D of this game object
// Bool values for jump & doublejump
private bool isGrounded = true;
private bool isJumpable = true; // Can player jump or doublejump?
// Inputs
private float horizontal = 0;
private bool jump = false;
// Variables for IsGrounded()
[SerializeField]
private LayerMask groundLayer;
[SerializeField]
private float rayDistance;
// Use this for initialization
void Start () {
......@@ -24,6 +34,40 @@ public class PlayerController : MonoBehaviour {
// Update is called once per frame
void Update () {
// TODO: Make moving algorithm
horizontal = Input.GetAxis("Horizontal");
if (Input.GetButtonDown("Jump"))
{
jump = true;
}
}
private void FixedUpdate()
{
isGrounded = IsGrounded();
if (isGrounded)
isJumpable = true;
float vertical = rb.velocity.y;
if (jump)
{
if (isGrounded)
{
vertical = jumpSpeed;
}
else if (isJumpable)
{
vertical = doubleJumpSpeed;
isJumpable = false;
}
}
rb.velocity = new Vector2(horizontal * speed * Time.fixedDeltaTime, vertical);
jump = false;
}
bool IsGrounded() // Is player grounded?
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, groundLayer);
Debug.DrawRay(transform.position, rayDistance* Vector2.down, Color.white);
return hit.collider != null;
}
}
......@@ -43,8 +43,8 @@ TextureImporter:
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 7
spritePivot: {x: 0.5, y: 0.5}
alignment: 0
spritePivot: {x: 0.5, y: 0}
spritePixelsToUnits: 64
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
......
......@@ -13,9 +13,9 @@ InputManager:
positiveButton: right
altNegativeButton: a
altPositiveButton: d
gravity: 3
gravity: 4
dead: 0.001
sensitivity: 3
sensitivity: 4
snap: 1
invert: 0
type: 0
......
......@@ -16,7 +16,7 @@ TagManager:
- UI
-
-
-
- Wall
-
-
-
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment