Commit 36fd7e99 authored by Parsa Rahmaty's avatar Parsa Rahmaty

The direction of the cannonballs is fixed

parent 94759b2c
......@@ -14,6 +14,7 @@ GameObject:
- component: {fileID: 400804237596747917}
- component: {fileID: 5560186350293350528}
- component: {fileID: 1317944747836374153}
- component: {fileID: 5687028221148072821}
m_Layer: 8
m_Name: Cannonball
m_TagString: Cannonball
......@@ -124,3 +125,15 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
speed: 30
--- !u!114 &5687028221148072821
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3972782314967972539}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e3cf5829d03eb97459c57901b7efff3d, type: 3}
m_Name:
m_EditorClassIdentifier:
......@@ -25,7 +25,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2984237215047306181}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 0, y: -1.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
......
......@@ -32,7 +32,7 @@ Transform:
m_GameObject: {fileID: 8953703217792660207}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 10, y: 0.25, z: 10}
m_LocalScale: {x: 10, y: 0.5, z: 10}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
......@@ -98,6 +98,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
rotationSpeed: 20
descendTime: 0.2
nodeHeight: 1
--- !u!114 &5704020906800342289
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -136,7 +137,7 @@ BoxCollider:
m_GameObject: {fileID: 8953703217792660207}
m_Material: {fileID: 13400000, guid: 767de626f0734e747b948a518e3e7918, type: 2}
m_IsTrigger: 0
m_Enabled: 1
m_Enabled: 0
serializedVersion: 2
m_Size: {x: 1.0000001, y: 2, z: 1.0000002}
m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697}
......
......@@ -149,7 +149,7 @@ Transform:
m_GameObject: {fileID: 58095958}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -2, z: 15}
m_LocalScale: {x: 30, y: 0.25, z: 30}
m_LocalScale: {x: 25, y: 0.25, z: 25}
m_Children: []
m_Father: {fileID: 768744113}
m_RootOrder: 0
......@@ -214,6 +214,37 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 58095958}
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &135398378
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 135398379}
m_Layer: 0
m_Name: Cannon Holder
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &135398379
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 135398378}
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: 1827272339}
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &446428163 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 2984237215047306180, guid: 90b16e9d09448504aa823b8ca0032ddf,
......@@ -518,7 +549,7 @@ Transform:
m_LocalScale: {x: 1, y: 0.5, z: 1}
m_Children: []
m_Father: {fileID: 1827272339}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!136 &1384577412
CapsuleCollider:
......@@ -612,7 +643,7 @@ Transform:
m_LocalScale: {x: 2, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1827272339}
m_RootOrder: 0
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1389915129
BoxCollider:
......@@ -674,6 +705,36 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1389915127}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1414855918
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1414855919}
m_Layer: 0
m_Name: Shooting Target
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1414855919
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1414855918}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1827272339}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1827272338
GameObject:
m_ObjectHideFlags: 0
......@@ -686,7 +747,7 @@ GameObject:
- component: {fileID: 1827272340}
m_Layer: 0
m_Name: Cannon
m_TagString: Player
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -702,10 +763,11 @@ Transform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1414855919}
- {fileID: 1389915128}
- {fileID: 1384577411}
m_Father: {fileID: 0}
m_RootOrder: 3
m_Father: {fileID: 135398379}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1827272340
MonoBehaviour:
......@@ -929,21 +991,6 @@ PrefabInstance:
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2984237215047306180, guid: 90b16e9d09448504aa823b8ca0032ddf,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2984237215047306180, guid: 90b16e9d09448504aa823b8ca0032ddf,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2984237215047306180, guid: 90b16e9d09448504aa823b8ca0032ddf,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2984237215047306180, guid: 90b16e9d09448504aa823b8ca0032ddf,
type: 3}
propertyPath: m_LocalRotation.x
......@@ -984,6 +1031,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2984237215047306180, guid: 90b16e9d09448504aa823b8ca0032ddf,
type: 3}
propertyPath: m_LocalPosition.y
value: -1.25
objectReference: {fileID: 0}
- target: {fileID: 2984237215047306181, guid: 90b16e9d09448504aa823b8ca0032ddf,
type: 3}
propertyPath: m_Name
......
This diff is collapsed.
fileFormatVersion: 2
guid: 128561e13f43bd346a528566cbe5223d
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -4,10 +4,27 @@ using UnityEngine;
public class Movable : MonoBehaviour
{
// Destination-based movement fields
private Vector3 startPosition;
public Vector3 targetPosition { get; private set; }
private float time;
private float timeToReachTarget;
//=====================================================
// Direction-based movement fields
private Vector3 direction;
private float speed;
private bool isOnWorldSpace;
//=====================================================
enum Mode
{
Destination,
Direction,
Neutral
}
private Mode mode = Mode.Neutral;
void Start()
{
......@@ -15,10 +32,17 @@ public class Movable : MonoBehaviour
}
void Update()
{
if (mode == Mode.Destination)
{
time += Time.deltaTime / timeToReachTarget;
transform.position = Vector3.Lerp(startPosition, targetPosition, time);
}
else if(mode == Mode.Direction)
{
transform.Translate(Vector3.Normalize(direction) * speed * Time.deltaTime, (isOnWorldSpace ? Space.World : Space.Self));
}
}
public void SetDestination(Vector3 destination, float time)
{
......@@ -26,5 +50,14 @@ public class Movable : MonoBehaviour
startPosition = transform.position;
timeToReachTarget = time;
targetPosition = destination;
mode = Mode.Destination;
}
public void SetDirection(Vector3 direction, float speed, bool isOnWorldSpace)
{
this.direction = direction;
this.speed = speed;
this.isOnWorldSpace = isOnWorldSpace;
mode = Mode.Direction;
}
}
......@@ -8,7 +8,7 @@ public class CannonControls : MonoBehaviour
[SerializeField] private float shootingDelay = 0.2f;
[SerializeField] private Collider[] cannonColliders = null;
private float delay;
private float framesLeftToShoot = 0f; // the number of frames passed since last shot
private float timeLeftToShoot = 0f; // the amount of time passed since last shot
void Start()
{
......@@ -19,28 +19,28 @@ public class CannonControls : MonoBehaviour
{
if(Input.GetKey(KeyCode.Space))
{
if (framesLeftToShoot <= 0f)
if (timeLeftToShoot <= 0f)
{
// start shooting cannonballs
GameObject childObject = Instantiate(projectile) as GameObject;
foreach (Collider collider in cannonColliders)
Physics.IgnoreCollision(childObject.GetComponent<SphereCollider>(), collider, true);
Physics.IgnoreCollision(childObject.GetComponent<Collider>(), collider, true);
childObject.transform.parent = gameObject.transform;
childObject.transform.localPosition = new Vector3(0, 0, 0);
childObject.transform.LookAt(GameObject.Find("Shooting Target").transform);
if(delay > (shootingDelay * 1f) / 2f)
delay *= 0.95f;
framesLeftToShoot = delay;
timeLeftToShoot = delay;
}
else
{
framesLeftToShoot -= Time.deltaTime;
timeLeftToShoot -= Time.deltaTime;
}
}
if (Input.GetKeyUp(KeyCode.Space))
{
delay = shootingDelay;
framesLeftToShoot = 0f;
timeLeftToShoot = 0f;
}
}
}
......@@ -4,13 +4,11 @@ using UnityEngine;
public class Cannonball : MonoBehaviour
{
public int speed = 10;
private new Rigidbody rigidbody;
public float speed = 10f;
void Awake()
{
rigidbody = GetComponent<Rigidbody>();
rigidbody.velocity = new Vector3(0, 0, speed);
GetComponent<Movable>().SetDirection(Vector3.forward, speed, false);
Destroy(this.gameObject, 1f);
}
......
......@@ -8,24 +8,23 @@ public class NodeHolder : MonoBehaviour
[SerializeField] private DestroyableObject stackNodeObject = null;
void Awake()
{
nodes = new LinkedList<DestroyableObject>();
}
public void MakeNodes(int numberOfNodes)
{
for(int i = 0; i < nodes.Count; i++)
if(nodes == null)
nodes = new LinkedList<DestroyableObject>();
for (int i = 0; i < nodes.Count; i++)
{
nodes.First.Value.Kill();
nodes.RemoveFirst();
}
// The linked list is now empty
float nodeHeight = stackNodeObject.gameObject.GetComponent<StackNode>().GetNodeHeight();
for(int i = 0; i < numberOfNodes; i++)
{
DestroyableObject node = Instantiate(stackNodeObject);
node.transform.parent = gameObject.transform;
node.transform.localPosition = new Vector3(0f, i * 0.5f, 0f);
//if(nodeHeight == 0f) nodeHeight = node.gameObject.GetComponent<StackNode>()
node.transform.localPosition = new Vector3(0f, i * nodeHeight, 0f);
nodes.AddLast(node);
}
}
......
......@@ -6,8 +6,8 @@ public class StackNode : MonoBehaviour
{
[SerializeField] private float rotationSpeed = 10f;
[SerializeField] private float descendTime = 0.2f;
[SerializeField] private float nodeHeight = 1f;
private float descendDistance = 0.5f;
private Movable movable;
private void Awake()
......@@ -25,13 +25,18 @@ public class StackNode : MonoBehaviour
transform.localEulerAngles += new Vector3(0f, rotationSpeed * Time.fixedDeltaTime, 0f);
}
private void Descend()
private void OnDestroy()
{
movable.SetDestination(movable.targetPosition - new Vector3(0f, descendDistance, 0f), descendTime);
GameEvents.instance.onHitEvent -= Descend;
}
private void OnDestroy()
public float GetNodeHeight()
{
GameEvents.instance.onHitEvent -= Descend;
return nodeHeight;
}
private void Descend()
{
movable.SetDestination(movable.targetPosition - new Vector3(0f, nodeHeight, 0f), descendTime);
}
}
......@@ -3,7 +3,7 @@
--- !u!55 &1
PhysicsManager:
m_ObjectHideFlags: 0
serializedVersion: 13
serializedVersion: 11
m_Gravity: {x: 0, y: -9.81, z: 0}
m_DefaultMaterial: {fileID: 0}
m_BounceThreshold: 2
......@@ -17,12 +17,11 @@ PhysicsManager:
m_ClothInterCollisionDistance: 0
m_ClothInterCollisionStiffness: 0
m_ContactsGeneration: 1
m_LayerCollisionMatrix: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8fffffff6fffffff2fffffff9ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_AutoSimulation: 1
m_AutoSyncTransforms: 0
m_ReuseCollisionCallbacks: 1
m_ClothInterCollisionSettingsToggle: 0
m_ClothGravity: {x: 0, y: -9.81, z: 0}
m_ContactPairsMode: 0
m_BroadphaseType: 0
m_WorldBounds:
......@@ -32,5 +31,4 @@ PhysicsManager:
m_FrictionType: 0
m_EnableEnhancedDeterminism: 0
m_EnableUnifiedHeightmaps: 1
m_SolverType: 0
m_DefaultMaxAngularSpeed: 7
m_DefaultMaxAngluarSpeed: 7
......@@ -4,7 +4,7 @@
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 20
productGUID: 21d8bd3464428934ba031177685f86ed
productGUID: 21a5c9b0a93b4a1459fa4214094e8009
AndroidProfiler: 0
AndroidFilterTouchesWhenObscured: 0
AndroidEnableSustainedPerformanceMode: 0
......@@ -13,7 +13,7 @@ PlayerSettings:
useOnDemandResources: 0
accelerometerFrequency: 60
companyName: DefaultCompany
productName: FireballsClone
productName: NewFireballsClone
defaultCursor: {fileID: 0}
cursorHotspot: {x: 0, y: 0}
m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1}
......
......@@ -3,8 +3,7 @@
--- !u!78 &1
TagManager:
serializedVersion: 2
tags:
- Cannonball
tags: []
layers:
- Default
- TransparentFX
......@@ -14,10 +13,10 @@ TagManager:
- UI
-
-
- Cannonball
- Stack Node
- Ground
- Stack
-
-
-
-
-
-
-
......
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