Skip to content

Commit

Permalink
Platform movement is reversed upon player collision below
Browse files Browse the repository at this point in the history
  • Loading branch information
karofmah committed Oct 15, 2023
1 parent bef82cc commit c956e42
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 4 deletions.
68 changes: 68 additions & 0 deletions Assets/Scenes/CraterTown.unity
Original file line number Diff line number Diff line change
Expand Up @@ -3388,6 +3388,7 @@ Transform:
- {fileID: 1746097628}
- {fileID: 1501441468}
- {fileID: 1785816777}
- {fileID: 1041212752}
m_Father: {fileID: 0}
m_RootOrder: 14
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -3496,6 +3497,73 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 17
m_LocalEulerAnglesHint: {x: 0.892, y: 73.8, z: 26.72}
--- !u!1 &1041212751
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1041212752}
- component: {fileID: 1041212753}
- component: {fileID: 1041212754}
m_Layer: 0
m_Name: GameObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1041212752
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1041212751}
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_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 974049643}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1041212753
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1041212751}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 3.6315613, y: 0.43898773, z: 3.6156006}
m_Center: {x: 0.0256958, y: -0.8325424, z: 0.008285522}
--- !u!114 &1041212754
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1041212751}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 99aed0618e383a64abfb9827baa90149, type: 3}
m_Name:
m_EditorClassIdentifier:
platformMovement: {fileID: 1746097631}
--- !u!1 &1042958923
GameObject:
m_ObjectHideFlags: 0
Expand Down
17 changes: 17 additions & 0 deletions Assets/Scripts/Platforms/PlatformCollision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatformCollision: MonoBehaviour
{

[SerializeField] private PlatformMovement platformMovement;
private List<Transform> startRoutepoints;
private void Start() {
startRoutepoints = platformMovement.routepoints;
}
private void OnTriggerEnter(Collider other) {
if(other.CompareTag("Player")){
platformMovement.routepoints.Reverse();
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Platforms/PlatformCollision.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions Assets/Scripts/Platforms/PlatformMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

public class PlatformMovement : MonoBehaviour
{
[SerializeField] private List<Transform> routepoints;
public List<Transform> routepoints;
[SerializeField] private float moveSpeed = 5f;
private int nextRoutepointIndex;
private float travelDistance;
private Collider sphereCollider;
private Collider meshCollider;

private void Start()
{
sphereCollider = GetComponent<SphereCollider>();
meshCollider = GetComponent<MeshCollider>();

nextRoutepointIndex = 0;

travelDistance = Vector3.Distance(routepoints[nextRoutepointIndex + 1].transform.position, transform.position);
Expand Down Expand Up @@ -38,9 +44,6 @@ private void MovePlatform()
{
moveSpeed = 2f;

Debug.Log("travel:" + travelDistance);
Debug.Log("current:" + currentDistance);

}else{
moveSpeed = 5f;
}
Expand All @@ -49,6 +52,7 @@ private void MovePlatform()
routepoints.Reverse();
nextRoutepointIndex = 0;
}

private void OnTriggerEnter(Collider other) {
if(other.CompareTag("Player")){
other.transform.SetParent(transform);
Expand Down

0 comments on commit c956e42

Please sign in to comment.