Add punching animation

This commit is contained in:
Sofia 2019-08-04 20:26:02 +03:00
parent 19f2eb97ce
commit fe99a10c20
3 changed files with 77 additions and 8 deletions

View File

@ -118,7 +118,7 @@ Transform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8334477035414792174}
m_Father: {fileID: 340836170559364036}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &6970513589971572751
@ -198,10 +198,41 @@ Transform:
m_LocalPosition: {x: -0.15, y: 0.45, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 3236373932878825813}
- {fileID: 340836170559364036}
m_Father: {fileID: 8489029732530782807}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &6171388266710565393
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 340836170559364036}
m_Layer: 0
m_Name: SubHand
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &340836170559364036
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6171388266710565393}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 3236373932878825813}
m_Father: {fileID: 8334477035414792174}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &8489029732241002798
GameObject:
m_ObjectHideFlags: 0
@ -393,6 +424,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
Body: {fileID: 8489029732530782792}
Hand: {fileID: 8334477035414792174}
SubHand: {fileID: 340836170559364036}
MoveSpeed: 50
BodySprite: {fileID: 8489029732241002784}
BodyAnim: {fileID: 7470056256336689202}
@ -402,6 +434,8 @@ MonoBehaviour:
HandRight: {fileID: 1270933798917005542}
HandMiddle: {fileID: 3118287694834230934}
CameraFX: {fileID: 0}
HandRetractSpeed: 10
HandRotationRetractSpeed: 300
--- !u!1 &8489029732599905358
GameObject:
m_ObjectHideFlags: 0

View File

@ -5715,12 +5715,17 @@ PrefabInstance:
propertyPath: CameraFX
value:
objectReference: {fileID: 963194229}
- target: {fileID: 8489029732599905344, guid: 14a47f86f9e45da45863a81716f2378b,
- target: {fileID: 8489029732530782806, guid: 14a47f86f9e45da45863a81716f2378b,
type: 3}
propertyPath: HandRotationRetractSpeed
value: 200
objectReference: {fileID: 0}
- target: {fileID: 8489029732241002784, guid: 14a47f86f9e45da45863a81716f2378b,
type: 3}
propertyPath: m_SortingLayer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 8489029732241002784, guid: 14a47f86f9e45da45863a81716f2378b,
- target: {fileID: 8489029732599905344, guid: 14a47f86f9e45da45863a81716f2378b,
type: 3}
propertyPath: m_SortingLayer
value: 3

View File

@ -8,6 +8,7 @@ namespace Saltosion.OneWeapon {
public Rigidbody2D Body;
public Transform Hand;
public Transform SubHand;
public float MoveSpeed = 50f;
public SpriteRenderer BodySprite;
@ -26,6 +27,11 @@ namespace Saltosion.OneWeapon {
private Vector2 GunLocation = new Vector2(0, -0.6f);
private Vector3 GunRotation = new Vector3(0, 0, -90);
public float HandRetractSpeed = 10;
public float HandRotationRetractSpeed = 300;
private float CurrentHandRotation = 0f;
private float CurrentHandDistance = 0f;
public bool IsMoving {
private set; get;
} = false;
@ -93,11 +99,34 @@ namespace Saltosion.OneWeapon {
}
bool Shoot = Input.GetButtonDown("Shoot");
if (Shoot && Gun != null) {
Gun.Shoot(LookDirection, Rotation);
CameraFX.StopFor(0.03f);
CameraFX.ScreenShake(4f);
if (Shoot) {
if (Gun != null) {
Gun.Shoot(LookDirection, Rotation);
CameraFX.StopFor(0.03f);
CameraFX.ScreenShake(4f);
} else if (CurrentHandDistance <= 0) {
CurrentHandDistance = 1.5f;
CurrentHandRotation = 100;
}
}
if (CurrentHandDistance > 0) {
CurrentHandDistance -= HandRetractSpeed * Time.deltaTime;
CurrentHandDistance = Mathf.Max(CurrentHandDistance, 0);
}
if (CurrentHandRotation > 0) {
CurrentHandRotation -= HandRotationRetractSpeed * Time.deltaTime;
CurrentHandRotation = Mathf.Max(CurrentHandRotation, 0);
}
Vector3 HandPosition = SubHand.localPosition;
HandPosition.y = -CurrentHandDistance;
SubHand.localPosition = HandPosition;
Vector3 HandRotation = SubHand.localEulerAngles;
HandRotation.z = CurrentHandRotation;
SubHand.localEulerAngles = HandRotation;
}
public void SetGun(Gun gun) {
@ -110,4 +139,5 @@ namespace Saltosion.OneWeapon {
Gun.transform.localEulerAngles = GunRotation;
}
}
}