Quantcast
Channel: Questions in topic: "please"
Viewing all articles
Browse latest Browse all 93

Block Collision Sliding off

$
0
0
I made an earlier question but I think i found the problem. but you guys are more experienced then i am so I'm just going to give the script for it. using UnityEngine; using System.Collections; public class BlockCharacterCollision { public static Contact? GetContactBlockCharacter(Vector3 blockPos, Vector3 pos, CharacterCollider collider) { Contact contactA = GetClosestPoint(blockPos, pos+collider.bottom); Contact contactB = GetClosestPoint(blockPos, pos+collider.top); Contact contact = contactA; if(contactB.sqrDistance < contact.sqrDistance) contact = contactB; if(contact.sqrDistance > collider.radius*collider.radius) return null; Vector3 dir = contact.delta.normalized * collider.radius; Vector3 capsulePoint = contact.b + dir; contact.b = capsulePoint; return contact; } private static Contact GetClosestPoint(Vector3 blockPos, Vector3 point) { Vector3 blockMin = blockPos - Vector3.one/2f; Vector3 blockMax = blockPos + Vector3.one/2f; Vector3 closest = point; for(int i=0; i<3; i++) { if (closest[i] > blockMax[i]) closest[i] = blockMax[i]; if (closest[i] < blockMin[i]) closest[i] = blockMin[i]; } return new Contact(closest, point); } } Hopefully, I wont, have to go on a journey to fix this, because I really can't go forward with this addition/abomination/bug

Viewing all articles
Browse latest Browse all 93

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>