Here is what I have currently
if (orientation == 1) {
if (Physics.Raycast (collisionRay1, out hit, rayLength)) {
if (hit.collider.tag == "Ground") // If the raycast is colliding with the ground
{
groundedJump = true;
groundedRotate = true;
} else // If the raycast is not colliding with the ground
{
groundedJump = true;
groundedRotate = false;
}
}
}
When the player is touching a ground object, it sets the two Grounded variables to true. I had intended to have it so if the raycast is colliding with ground, then Grounded would be true, and if it wasn’t (else) then grounded would be set to false. But that isn’t happening. I originally set it so that every time I jumped, they were both set to false. The problem is that if I simply fall off a platform (Rather than jumping), the two Grounded variables remain at true.
Part 2:
using UnityEngine;
using System.Collections;
public class CameraRotation : MonoBehaviour {
public PlatformerController platformerController;
// Use this for initialization
void Start ()
{
platformerController = GetComponent<PlatformerController> ();
}
// Update is called once per frame
void Update ()
{
if ((Input.GetKeyDown ("down")) && (platformerController.groundedRotate == true))
{
transform.eulerAngles = new Vector3 (transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z - 90);
}
}
}
^^^This is the script I’m using on my camera. The script attached to playerOne is the PlatformerController C# script.
So if the player has groundedRotate set to true, it allows that player to do a 90 degree rotation. At the same time, I’m wanting the camera script to reference it, so that if the player’s script variable groundedRotate is true, then the camera will also perform a 90 degree rotation. The problem is that the code I’m using to reference it obviously isn’t correct.
So for the second part, rather than trying to access a script on playerOne, I’m just going to have playerOne access the camera’s component. Referencing scripts just doesn’t seem to work for me, but at least referencing the standard components isn’t too hard.
For the first part, I’m still stuck. When a player is falling, the raycast collider shouldn’t be colliding with anything that isn’t ground ( I only have it extending 0.1 units beyond the player ), yet it still shows that the player is grounded, which I need to not happen. The if/else statement doesn’t appear to be doing it’s job, or maybe it just wasn’t designed to work like that, I don’t know. I hate to bump, but without a fix the core fundamental of the game is broken. I can always set grounded to false automatically if I jump, but the problem is when the player simply falls off of something without jumping, as they’re falling grounded remains true.
There are a few of us who take pity on the “0 responses” threads we see laying around and put in a bit more effort than normal to get them solved after a day or two. “A bit more effort than normal” is necessary when the code posted is lacking in formatting. Anyways, I overlooked this one completely- my apologies.
I don’t see your issue with the single “grounded” variable approach. If you’re constantly checking the ground distance (you should also maybe be checking the “normal” of the impact point to make sure it’s pointed more or less upwards btw, so an excessively steep ground angle removes your control of the char). If you’re in the air, you’re not grounded and shouldn’t be able to jump- if you’re on the ground, then pressing the jump button applies an instant force that pushes the char upward and disconnects him from the ground. Falling off of a cliff should have exactly the same effect as jumping.
What exactly is “orientation”? Do you truly want to skip over the entire raycasting sequence if orientation isn’t 1? Unless you have some sort of default values set in an “else” statement for when orientation isn’t 1, then your grounding status is going to be stuck at whatever it was immediately before the orientation changed.
I’m attaching a file for the “Tutorial” scene in my game so you can better understand what I’m going for. Orientation is simply which way the character is “Rotated”, but not in a traditional sense. I have 4 different raycasts set up, one for each orientation value.
Assuming this file uploads correctly, it’s just a single scene from the game. I thought it would be interesting to have the input solely through the directional arrow keys. Left and right moves left and right obviously, up is jump, and down is a rotational shift (Which also changes the Orientation variable).
Besides getting a better idea of what I’m going for, please let me know what you think of the concept of the game. I’m ultimately going for a puzzle/platformer. It’ll start off fairly easy, but I’m in the middle of working out a good difficulty curve so that the later levels can be completed with some effort by the player.
When playing the demo, it is important to know that the level itself is remaining stationary. The player and the camera are rotating, and the gravity is shifting. I did this so that it would easier to make small changes to level design as I imagine I’ll wind up spending a lot of time running levels repeatedly to make sure everything is good.
Edit
Alright apparently the “Upload a file” feature doesn’t actually work, or perhaps is just temporarily down.