Moving platform/player rotation

Hi, this will probably be simple question for some of you, since I am self learning unity, scripting is kind of confusing to me.

Here is my code:

        public GameObject rotateScale;
        public GameObject player;

void Start(){
            rotateScale = GameObject.Find ("FixScaleRotate");
            player = GameObject.Find ("Player");
        }

void OnTriggerEnter(Collider other){

        if (other.tag == "Player") {
            //player.transform.parent = null;
            //player.transform.localScale = new Vector3 (1f, 1f, 1f);
            player.transform.parent = rotateScale.transform;
        }
    }

    void OnTriggerExit(Collider other){
        if (other.tag == "Player") {
            player.transform.parent = null;
        }
    }

The problem is when I jump on moving platform, player goes under FixScaleRotate(empty object) witch is child of moving platform, the players sticks to it fine but when player collides with platform it rotates, and when on trigger is broken it goes back to rotation where player was before jumping on platform. I think that there is simple solution for this but my mind cant get hold on it. Some ideas?

First, please use code tags: Using code tags properly - Unity Engine - Unity Discussions

It makes it much easier to read your code. Also, next time post in the Scripting section of the forums, you’ll get more answers for C# questions there :slight_smile:

How does your player switch platforms? Do you use a button and jump between them? I think you could just make a bool, where if OnTriggerEnter has been called, OnTriggerExit doesn’t work unless you’re on a new platform (if that’s what you want to do).

Sry for bad code look, I edited it. This is my first post on unity forums. :smile:

Player switch platform by jumping from static to rotating platform and vice versa. Sticking to rotating platform works fine but rotation of player is the problem. Camera rotates for 90* when player jumps on rotating platform and when he jumps back camera resets to position it was before jumping on rotating platform. I am not sure if bool will fix that?

Edit:

I have found that my mouse moving script is making the problem. Do you have some good scripts for first person char? :slight_smile:

No, I have good curiosity on how to make my own scripts, and less ability to actually make them :slight_smile:

There’s first person character scripts in the Standard Assets and on the Asset Store as well.

Basically, my idea was instead of using OnTriggerExit, OnTriggerEnter, you can check what platform the player is on and based on that, execute some code. I’d a few times a second shoot a raycast down from the player’s position and get the platform object in a RaycastHit. That way I’d always know what’s under the player, and based on what’s under the player I could execute code.

Obviously I can’t tell you word-by-word what to do since I have no idea what you’re trying to achieve, but that’s the jist of it.

1 Like

Hmm I get what you are aiming at, but since I am new to all of this even raycast is new to me. I will explore as much of youtube tutorials as I can and hope to come with some fix for this. Tnx anyway m8. :smile: