Browse Source

add: player movement

master
KerelOlivier 3 years ago
parent
commit
4d9862a2b0
  1. 13
      .idea/.idea.LD50/.idea/.gitignore
  2. 4
      .idea/.idea.LD50/.idea/encodings.xml
  3. 8
      .idea/.idea.LD50/.idea/indexLayout.xml
  4. 6
      .idea/.idea.LD50/.idea/vcs.xml
  5. 8
      Assets/Input.meta
  6. 109
      Assets/Input/Player.inputactions
  7. 14
      Assets/Input/Player.inputactions.meta
  8. 157
      Assets/Scenes/test.unity
  9. 53
      Assets/Scripts/PlayerController.cs
  10. 11
      Assets/Scripts/PlayerController.cs.meta
  11. BIN
      Assets/Sprites/Player.png
  12. 120
      Assets/Sprites/Player.png.meta
  13. 1
      Packages/manifest.json
  14. 9
      Packages/packages-lock.json
  15. 2
      ProjectSettings/ProjectSettings.asset

13
.idea/.idea.LD50/.idea/.gitignore vendored

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/modules.xml
/.idea.LD50.iml
/contentModel.xml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

4
.idea/.idea.LD50/.idea/encodings.xml

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

8
.idea/.idea.LD50/.idea/indexLayout.xml

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

6
.idea/.idea.LD50/.idea/vcs.xml

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

8
Assets/Input.meta

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0366a53eb4119ab5ba6501929f29eef6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

109
Assets/Input/Player.inputactions

@ -0,0 +1,109 @@ @@ -0,0 +1,109 @@
{
"name": "Player",
"maps": [
{
"name": "default",
"id": "83ceaef8-7a9f-40f7-8e71-469b434b3d9a",
"actions": [
{
"name": "Move",
"type": "Value",
"id": "1163ce9d-c7cb-41b7-b122-5360af9d9773",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "Fight",
"type": "Button",
"id": "9b6e6f96-096c-4d0e-ad98-05be447902a7",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
{
"name": "WASD",
"id": "47d8955c-bf93-4735-804c-3b7dc82985c8",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "949f9fa2-bf12-4f98-a1ec-4ca563c0566a",
"path": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "d9753777-7aaf-4e86-bbbc-a49cd33935dc",
"path": "<Keyboard>/s",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "298f5cd4-04fe-4b2f-bd82-c1536d59658b",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "373de430-6124-4b20-a2c1-e3f0704857ba",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "d6733eac-0ba0-49b9-af28-85a00c268050",
"path": "<Keyboard>/space",
"interactions": "",
"processors": "",
"groups": "",
"action": "Fight",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "c9b00421-6536-4edf-96cf-4e4f19a30c1b",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": "",
"action": "Fight",
"isComposite": false,
"isPartOfComposite": false
}
]
}
],
"controlSchemes": []
}

14
Assets/Input/Player.inputactions.meta

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 072cf7ce024a1a2ee8707f72b713be30
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 0
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace:

157
Assets/Scenes/test.unity

@ -132,6 +132,11 @@ GameObject: @@ -132,6 +132,11 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 394882246}
- component: {fileID: 394882247}
- component: {fileID: 394882248}
- component: {fileID: 394882250}
- component: {fileID: 394882249}
- component: {fileID: 394882251}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
@ -153,6 +158,156 @@ Transform: @@ -153,6 +158,156 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &394882247
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 394882245}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: ea7869a6d259396a0a452fe8ff118af0, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &394882248
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 394882245}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Actions: {fileID: -944628639613478452, guid: 072cf7ce024a1a2ee8707f72b713be30, type: 3}
m_NotificationBehavior: 2
m_UIInputModule: {fileID: 0}
m_DeviceLostEvent:
m_PersistentCalls:
m_Calls: []
m_DeviceRegainedEvent:
m_PersistentCalls:
m_Calls: []
m_ControlsChangedEvent:
m_PersistentCalls:
m_Calls: []
m_ActionEvents:
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName:
m_MethodName:
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName:
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_ActionId: 1163ce9d-c7cb-41b7-b122-5360af9d9773
m_ActionName: default/Movement[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 9b6e6f96-096c-4d0e-ad98-05be447902a7
m_ActionName: default/Fight[/Keyboard/space,/Mouse/leftButton]
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme:
m_DefaultActionMap: default
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}
--- !u!58 &394882249
CircleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 394882245}
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}
serializedVersion: 2
m_Radius: 0.37
--- !u!50 &394882250
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 394882245}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 0.0001
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 0
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!114 &394882251
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 394882245}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ff7058e4b6f609474b877ecc3d8c9e62, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0
@ -189,7 +344,7 @@ Camera: @@ -189,7 +344,7 @@ Camera:
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_BackGroundColor: {r: 0.4245283, g: 0.4245283, b: 0.4245283, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0

53
Assets/Scripts/PlayerController.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
private Rigidbody2D rb;
private SpriteRenderer sr;
private Camera main;
//Input
private PlayerInput input;
private InputAction moveAction;
private InputAction fightAction;
private Vector2 moveDirection;
private float moveSpeed = 5f;
// Start is called before the first frame update
private void Awake()
{
rb = this.gameObject.GetComponent<Rigidbody2D>();
input = this.gameObject.GetComponent<PlayerInput>();
moveAction = input.actions["Move"];
fightAction = input.actions["Fight"];
//Input events
moveAction.performed += ctx => Move(ctx.ReadValue<Vector2>());
moveAction.canceled += ctx => Move(Vector2.zero);
main = Camera.main;
}
private void FixedUpdate()
{
//Update move direction
rb.MovePosition(rb.position + moveDirection * moveSpeed * Time.fixedDeltaTime);
}
private void Update()
{
//Update the sprite direction based on mouse position
Vector2 mousePos = main.ScreenToWorldPoint(Mouse.current.position.ReadValue());
Vector2 direction = mousePos - (Vector2)transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
//update the move direction
void Move(Vector2 direction) => moveDirection = direction;
}

11
Assets/Scripts/PlayerController.cs.meta

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ff7058e4b6f609474b877ecc3d8c9e62
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Sprites/Player.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

120
Assets/Sprites/Player.png.meta

@ -0,0 +1,120 @@ @@ -0,0 +1,120 @@
fileFormatVersion: 2
guid: ea7869a6d259396a0a452fe8ff118af0
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 64
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

1
Packages/manifest.json

@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
"com.unity.ide.rider": "2.0.7",
"com.unity.ide.visualstudio": "2.0.14",
"com.unity.ide.vscode": "1.2.5",
"com.unity.inputsystem": "1.3.0",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.4.8",

9
Packages/packages-lock.json

@ -113,6 +113,15 @@ @@ -113,6 +113,15 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.inputsystem": {
"version": "1.3.0",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.modules.uielements": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.mathematics": {
"version": "1.1.0",
"depth": 1,

2
ProjectSettings/ProjectSettings.asset

@ -650,7 +650,7 @@ PlayerSettings: @@ -650,7 +650,7 @@ PlayerSettings:
m_VersionCode: 1
m_VersionName:
apiCompatibilityLevel: 6
activeInputHandler: 0
activeInputHandler: 1
cloudProjectId:
framebufferDepthMemorylessMode: 0
qualitySettingsNames: []

Loading…
Cancel
Save