Fixed weird collision angles.
This commit is contained in:
parent
bab441e902
commit
11a517ba60
14
Assets/Materials/PlayerMaterial.physicMaterial
Normal file
14
Assets/Materials/PlayerMaterial.physicMaterial
Normal file
@ -0,0 +1,14 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!134 &13400000
|
||||
PhysicMaterial:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: PlayerMaterial
|
||||
dynamicFriction: 0.6
|
||||
staticFriction: 0.6
|
||||
bounciness: 0
|
||||
frictionCombine: 1
|
||||
bounceCombine: 0
|
8
Assets/Materials/PlayerMaterial.physicMaterial.meta
Normal file
8
Assets/Materials/PlayerMaterial.physicMaterial.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 055b414bc685d41409a41f4ea2d64231
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 13400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -972,6 +972,24 @@ Transform:
|
||||
m_CorrespondingSourceObject: {fileID: 8768991388683709944, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3}
|
||||
m_PrefabInstance: {fileID: 613611969}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1 &1172583617 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 3244356566819001084, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
m_PrefabInstance: {fileID: 1953646381}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!65 &1172583624
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1172583617}
|
||||
m_Material: {fileID: 13400000, guid: 055b414bc685d41409a41f4ea2d64231, type: 2}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 1, y: 2, z: 1}
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!4 &1210902573 stripped
|
||||
Transform:
|
||||
m_CorrespondingSourceObject: {fileID: 8768991388683709944, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3}
|
||||
@ -1053,6 +1071,22 @@ PrefabInstance:
|
||||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 3244356566819001072, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
propertyPath: m_Enabled
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3244356566819001073, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
propertyPath: m_Enabled
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3244356566819001085, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 0.11
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3244356566819001087, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
propertyPath: m_CollisionDetection
|
||||
value: 2
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3244356567786994344, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: Player
|
||||
@ -1101,6 +1135,14 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3244356567913423212, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 0.55
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3244356567913423212, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 0.5
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
--- !u!4 &2009655149 stripped
|
||||
|
@ -24,6 +24,8 @@ public class PlayerController : MonoBehaviour
|
||||
private bool isGrounded = false;
|
||||
public bool isRunning = false;
|
||||
|
||||
private Vector3 downDirection;
|
||||
|
||||
private Vector3 follow = Vector3.zero;
|
||||
|
||||
void Start()
|
||||
@ -70,7 +72,7 @@ public class PlayerController : MonoBehaviour
|
||||
{
|
||||
if (other.gameObject.tag == "platform")
|
||||
{
|
||||
Physics.gravity = -Vector3.up * 9.81f;
|
||||
Physics.gravity = this.downDirection * 9.81f;
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,12 +88,27 @@ public class PlayerController : MonoBehaviour
|
||||
Vector3 axis;
|
||||
float angle;
|
||||
axis = Vector3.Cross(-transform.up, -other.GetContact(0).normal);
|
||||
|
||||
if (other.GetContact(0).normal == other.transform.forward
|
||||
|| other.GetContact(0).normal == -other.transform.forward
|
||||
|| (
|
||||
other.GetContact(0).normal != -other.transform.up
|
||||
&& other.GetContact(0).normal != other.transform.up
|
||||
&& other.GetContact(0).normal != -other.transform.right
|
||||
&& other.GetContact(0).normal != other.transform.right
|
||||
)
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Physics.gravity = this.downDirection * 9.81f;
|
||||
if (platform.type == PlatformManager.PlatformType.SpeedUp)
|
||||
{
|
||||
angle = Mathf.Atan2(Vector3.Magnitude(axis), Vector3.Dot(-transform.up, -other.GetContact(0).normal));
|
||||
transform.RotateAround(axis, angle);
|
||||
// TODO: Rotate gravity to the center of platform
|
||||
}
|
||||
// TODO: Handle other PlatformTypes
|
||||
Physics.gravity = this.downDirection * 9.81f;
|
||||
|
||||
}
|
||||
|
||||
@ -100,6 +117,18 @@ public class PlayerController : MonoBehaviour
|
||||
isGrounded = true;
|
||||
if (other.gameObject.tag == "platform")
|
||||
{
|
||||
if (other.GetContact(0).normal == other.transform.forward
|
||||
|| other.GetContact(0).normal == -other.transform.forward
|
||||
|| (
|
||||
other.GetContact(0).normal != -other.transform.up
|
||||
&& other.GetContact(0).normal != other.transform.up
|
||||
&& other.GetContact(0).normal != -other.transform.right
|
||||
&& other.GetContact(0).normal != other.transform.right
|
||||
)
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Vector3 axis;
|
||||
float angle;
|
||||
|
||||
@ -114,6 +143,8 @@ public class PlayerController : MonoBehaviour
|
||||
PlatformManager platform = other.gameObject.GetComponent<PlatformManager>();
|
||||
gDirection = -transform.up;
|
||||
if (platform == null){
|
||||
// FIXME: remove
|
||||
this.downDirection = -transform.up;
|
||||
return;
|
||||
}
|
||||
if (platform.type == PlatformManager.PlatformType.Pull)
|
||||
@ -138,6 +169,7 @@ public class PlayerController : MonoBehaviour
|
||||
rb.AddForce(other.transform.forward * platform.speed * 10 * Time.deltaTime, ForceMode.Impulse);
|
||||
gDirection = -transform.up;
|
||||
}
|
||||
this.downDirection = gDirection;
|
||||
|
||||
Physics.gravity = gDirection * 9.81f;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user