Merge pull request #1 from Games-Academy-Student-Work-21-22/cannon-movement

Added cannon movement with constraints
This commit is contained in:
Philip W 2021-10-29 22:26:52 +01:00 committed by GitHub Enterprise
commit 966ff2b9a1
6 changed files with 952 additions and 674 deletions

View File

@ -5,7 +5,7 @@
<resetOnSceneChange>false</resetOnSceneChange>
<debugMode>false</debugMode>
<EditorClosed>true</EditorClosed>
<LastTimestamp>1635426319</LastTimestamp>
<LastSessionID>4444499006469112348</LastSessionID>
<LastTimestamp>1635463125</LastTimestamp>
<LastSessionID>978925994938979108</LastSessionID>
<Errored>false</Errored>
</ERPSettings>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,63 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!850595691 &4890085278179872738
LightingSettings:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: DefenderSettings
serializedVersion: 3
m_GIWorkflowMode: 1
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_RealtimeEnvironmentLighting: 1
m_BounceScale: 1
m_AlbedoBoost: 1
m_IndirectOutputScale: 1
m_UsingShadowmask: 0
m_BakeBackend: 0
m_LightmapMaxSize: 1024
m_BakeResolution: 40
m_Padding: 2
m_TextureCompression: 1
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 0
m_CompAOExponentDirect: 0
m_ExtractAO: 0
m_MixedBakeMode: 1
m_LightmapsBakeMode: 1
m_FilterMode: 1
m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0}
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_RealtimeResolution: 2
m_ForceWhiteAlbedo: 0
m_ForceUpdates: 0
m_FinalGather: 0
m_FinalGatherRayCount: 1024
m_FinalGatherFiltering: 1
m_PVRCulling: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVREnvironmentSampleCount: 500
m_PVREnvironmentReferencePointCount: 2048
m_LightProbeSampleCountMultiplier: 4
m_PVRBounces: 2
m_PVRMinBounces: 2
m_PVREnvironmentMIS: 0
m_PVRFilteringMode: 0
m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0
m_PVRDenoiserTypeAO: 0
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a4a9c54780ce0f24a9b965760cb8393a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 4890085278179872738
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class MoveHorizontalConstrained : Physics2DObject
{
[Header("Input keys")]
public Enums.KeyGroups typeOfControl = Enums.KeyGroups.ArrowKeys;
[Header("Movement")]
[Tooltip("Speed of movement")]
public float speed = 5f;
[Header("Movement Constraint")]
[Tooltip("How Far Movement is Constrained")]
public float constrainedDistance = 5f;
private Vector2 movement;
private float moveHorizontal, initalPositionX, constraintOffsetXPosition;
//Is called once when object is created
void Start()
{
//Gets positional offset from current position
initalPositionX = this.transform.position.x;
constraintOffsetXPosition = initalPositionX + constrainedDistance;
}
// Update is called once per frame
void Update()
{
//Gets input from either the arrow keys or WASD
if (typeOfControl == Enums.KeyGroups.ArrowKeys)
{
moveHorizontal = Input.GetAxis("Horizontal");
}
else
{
moveHorizontal = Input.GetAxis("Horizontal2");
}
//Defines Horizontal Movement
movement = new Vector2(moveHorizontal, 0f);
}
//FixedUpdate is called every frame when the physics are calculated
void FixedUpdate()
{
//Sets the objects velocity to 0 if it hits the constrained bounds
if ((this.transform.position.x >= constraintOffsetXPosition && moveHorizontal >= 0f) || (this.transform.position.x <= (constraintOffsetXPosition * -1) && moveHorizontal <= 0f))
{
rigidbody2D.velocity = new Vector2(0f, 0f);
}
else
{
//Apply the force to the Rigidbody2d
rigidbody2D.AddForce(movement * speed * 5f);
}
}
}

View File

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