Commit c8df013e authored by Sebastian Frey's avatar Sebastian Frey
Browse files

fixed MovableObjects

parent 888bafc5
......@@ -13,8 +13,8 @@ GameObject:
- component: {fileID: 70840632841850180}
- component: {fileID: 212152556601460820}
- component: {fileID: 5567333940966867164}
m_Layer: 0
m_Name: Pre_PlayerFireAttack
m_Layer: 12
m_Name: FireAttack
m_TagString: Fire
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
......
......@@ -142,3 +142,4 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
destroyTime: 3
pushFactor: 5
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6184296985288555399
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8257885254229348828}
- component: {fileID: 3590286897431027205}
- component: {fileID: 4292658995770755931}
m_Layer: 0
m_Name: GameObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8257885254229348828
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6184296985288555399}
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: []
m_Father: {fileID: 7732554449417407852}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &3590286897431027205
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6184296985288555399}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &4292658995770755931
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6184296985288555399}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5c135c3fe901cf4696abeebd2ac1f28, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &6240296448730384320
GameObject:
m_ObjectHideFlags: 0
......@@ -10,7 +80,8 @@ GameObject:
m_Component:
- component: {fileID: 7732554449417407852}
- component: {fileID: 1297297354442121813}
- component: {fileID: 2063039573222851098}
- component: {fileID: 7986769661104333248}
- component: {fileID: 762648849805719858}
m_Layer: 9
m_Name: Movable_Thing
m_TagString: Untagged
......@@ -28,7 +99,8 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 133.12, y: 41.63, z: -0.017713891}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Children:
- {fileID: 8257885254229348828}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
......@@ -80,16 +152,50 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &2063039573222851098
MonoBehaviour:
--- !u!50 &7986769661104333248
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6240296448730384320}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!61 &762648849805719858
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6240296448730384320}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5c135c3fe901cf4696abeebd2ac1f28, type: 3}
m_Name:
m_EditorClassIdentifier:
force: 0
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 2, y: 2}
newSize: {x: 2, y: 2}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 2, y: 2}
m_EdgeRadius: 0
......@@ -256,7 +256,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
cooldown: 1
massIncrease: 30
massIncrease: 5
isStomping: 0
--- !u!114 &352228605
MonoBehaviour:
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SliderObject : MonoBehaviour
namespace _Game.Scripts.Level_Hazards
{
private Rigidbody2D rb;
public float force;
/*private void OnTriggerEnter2D(Collider2D collision)
public class SliderObject : MonoBehaviour
{
if (!GetComponent<Rigidbody2D>())
{
rb = GetComponent<Rigidbody2D>();
}
else
private Vector2 _position;
private Rigidbody2D _rigidbody2D;
private void Start()
{
Debug.Log("Kein Rigidbody");
_rigidbody2D = this.GetComponentInParent<Rigidbody2D>();
}
if (collision.gameObject.CompareTag("Water"))
private void OnCollisionEnter2D(Collision2D other)
{
if(collision.transform.position.x > GetComponent<Transform>().position.x)
{
rb.AddForce(new Vector2(-force, 0));
}else if (collision.transform.position.x < GetComponent<Transform>().position.x)
if (other.gameObject.layer == LayerMask.NameToLayer("Player") || other.gameObject.layer == LayerMask.NameToLayer("Enemy") ||
other.gameObject.CompareTag("Fire"))
{
rb.AddForce(new Vector2(force, 0));
_rigidbody2D.velocity = Vector2.zero;
_rigidbody2D.bodyType = RigidbodyType2D.Static;
}
}
}*/
private void OnCollisionEnter2D(Collision2D other)
{
if (other.transform.gameObject.tag.Equals("Water"))
{
gameObject.GetComponent<Rigidbody2D>().velocity = other.gameObject.GetComponent<Rigidbody2D>().velocity;
}
}
private void OnCollisionExit2D(Collision2D other)
{
if (other.transform.gameObject.tag.Equals("Water"))
private void OnCollisionExit2D(Collision2D other)
{
gameObject.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
if (other.gameObject.layer == LayerMask.NameToLayer("Player") || other.gameObject.layer == LayerMask.NameToLayer("Enemy") ||
other.gameObject.CompareTag("Fire"))
{
_rigidbody2D.velocity = Vector2.zero;
_rigidbody2D.bodyType = RigidbodyType2D.Dynamic;
}
}
}
}
......@@ -5,6 +5,7 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water
public class PlayerWaterProjectile : MonoBehaviour
{
public float destroyTime = 2.0f;
public float pushFactor = 1.0f;
private float _startTime;
private float _deltaTime;
private float _newScaleFactor;
......@@ -18,7 +19,6 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water
_startTime = Time.time;
_startingScale = this.gameObject.transform.localScale;
_rigidbody2D = GetComponent<Rigidbody2D>();
_startingVelocity = _rigidbody2D.velocity;
}
private void Update()
......@@ -38,6 +38,24 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water
this.gameObject.transform.localScale = _newScaleVector;
}
public void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.layer != LayerMask.NameToLayer("Ground"))
{
if (other.gameObject.layer == LayerMask.NameToLayer("MovableObject"))
{
if (Mathf.Abs(_rigidbody2D.velocity.x) > 0.0001f)
{
var projectileVelocityX = _rigidbody2D.velocity.x / Mathf.Abs(_rigidbody2D.velocity.x);
print(projectileVelocityX);
other.gameObject.GetComponent<Rigidbody2D>().velocity = new Vector3(projectileVelocityX * pushFactor, 0.0f, 0.0f);
}
}
Destroy();
}
}
private void OnEnable()
{
Invoke(nameof(Destroy), destroyTime);
......
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