feat: collision with a spike (#28)

This commit is contained in:
2024-12-16 16:19:59 +01:00
committed by GitHub
parent d8e3cd824d
commit 1b7912893f
6 changed files with 418 additions and 67 deletions

View File

@ -2,20 +2,22 @@ using UnityEngine;
public class Obstacle : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
public PlayerScript playerScript;
public GameObject playerObject;
public void Start()
{
playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerScript>();
}
// Update is called once per frame
void Update()
public void Update()
{
}
public void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("Test");
playerObject.transform.rotation = playerScript.initialRotation;
playerObject.transform.position = playerScript.initialPosition;
}
}

View File

@ -6,20 +6,21 @@ public class PlayerScript : MonoBehaviour
public GameObject groundObject;
public Vector3 initialPosition;
public Quaternion initialRotation;
public ParticleSystem particleSystem;
public ParticleSystem particle;
private bool wantsToJump = false;
private bool isGrounded = true;
public void Start()
{
initialPosition = transform.position;
initialRotation = transform.rotation;
var mainModule = particleSystem.main;
var mainModule = particle.main;
mainModule.simulationSpace = ParticleSystemSimulationSpace.World;
particleSystem.transform.parent = null;
particle.transform.parent = null;
}
public void Update()
@ -37,7 +38,6 @@ public class PlayerScript : MonoBehaviour
if (!IsJumping())
{
isGrounded = true;
AlignRotation();
if (wantsToJump)
@ -46,12 +46,11 @@ public class PlayerScript : MonoBehaviour
wantsToJump = false;
}
particleSystem.gameObject.SetActive(true);
particle.gameObject.SetActive(true);
}
else
{
isGrounded = false;
particleSystem.gameObject.SetActive(false);
particle.gameObject.SetActive(false);
transform.Rotate(Vector3.back * 360 * Time.deltaTime);
}
@ -79,13 +78,13 @@ public class PlayerScript : MonoBehaviour
private void UpdateParticlePositionAndRotation()
{
particleSystem.transform.position = transform.position + new Vector3(-0.19f, -0.64f, 0);
particleSystem.transform.rotation = Quaternion.Euler(0, 0, 150.464f);
particle.transform.position = transform.position + new Vector3(-0.19f, -0.64f, 0);
particle.transform.rotation = Quaternion.Euler(0, 0, 150.464f);
}
private void UpdateParticleSystemSpeed()
{
var velocityOverLifetime = particleSystem.velocityOverLifetime;
var velocityOverLifetime = particle.velocityOverLifetime;
velocityOverLifetime.x = rigidBody.linearVelocity.x;
}
}

View File

@ -0,0 +1,23 @@
using UnityEngine;
public class SpikeScript : MonoBehaviour
{
public PlayerScript playerScript;
public GameObject playerObject;
public void Start()
{
playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerScript>();
}
public void Update()
{
}
public void OnTriggerEnter2D(Collider2D collision)
{
playerObject.transform.rotation = playerScript.initialRotation;
playerObject.transform.position = playerScript.initialPosition;
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5b6c5b0fa69a1f00da3d8c4aa96485f3