Making a 2D platformer and having trouble figuring out how to solve/create a One-Way-Platform when I am using raycasts for collusion detection. As for what a One-Way-Platform is: a platform a player can jump on top of from underneath and stand/run on. And the player does not collide with the platform from the sides.
Here's a small sample of the raycast code I use to detection the collusion with a ceiling, wall, or floor in C Sharp:
Vector3 pos;
void Update () {
ceilHeight = Mathf.Min(Raycast(Vector2.up, pos).y, Raycast(Vector2.up, pos).y);
floorHeight = Mathf.Max(Raycast(-Vector2.up, pos).y, Raycast(-Vector2.up, pos).y);
rightConstraint = Mathf.Min(Raycast(Vector2.right, pos).x, Raycast(Vector2.right, pos).x);
leftConstraint = Mathf.Max(Raycast(-Vector2.right, pos).x, Raycast(-Vector2.right, pos).x);
}
And here's the same code written in Javascript/Unityscript:
var pos : Vector3;
function Update() {
ceilHeight = Mathf.Min(Raycast(Vector2.up, pos).y, Raycast(Vector2.up, pos).y);
floorHeight = Mathf.Max(Raycast(-Vector2.up, pos).y, Raycast(-Vector2.up, pos).y);
rightConstraint = Mathf.Min(Raycast(Vector2.right, pos).x, Raycast(Vector2.right, pos).x);
leftConstraint = Mathf.Max(Raycast(-Vector2.right, pos).x, Raycast(-Vector2.right, pos).x);
}
There is more to the code to make total sense, but I'm sure this is all that is needed to understand how the Raycasts are being used.
If I could find a way to have Raycasts make exclusions to One-Way-Platform GameObjects, by seeing what they are hitting, this could be useful for when I code moving platforms the player is standing on as well. I'm not sure how to do this yet since I have never created this.
Any suggestions?
↧