align player to object location in C#?
Hey all, I'm working on a prototype for the sequel to a game I made a while ago called Goat Basement:
https://play.google.com/store/apps/details?id=goatBasement.sprocketForge
Part of the gameplay I want to implement is switching between 2D and 3D game space, using trigger volumes. In other words, the player object crosses one volume that makes the player switch from sidescroller mode to 3D, and another that makes the switch back to 2D.
My current problem is that when you switch back to 2D, you're still pointed in the direction in which you went through the volume, so you almost always immediately rocket off the side of the 2D platform area. My proposed solution for this is to create an empty child object of the trigger volume and have the player object snap to the empty object's rotation and Z position.
I'm still relatively new to scripting and am unsure of how exactly to go about this. Here is the current code (not working, of course) for the 2D switching volume.
Any help or guidance would be greatly appreciated.
using UnityEngine; using System.Collections;
public class POVUnswitch : MonoBehaviour {
// Use this for initialization
void Start () {
}
void OnTriggerEnter(Collider other)
{ GameObject Player = GameObject.Find("Player");
GameObject ExitCube = GameObject;
CharacterMotor playerScript = Player.GetComponent<CharacterMotor>();
PlayerMove moveScript = Player.GetComponent<PlayerMove> ();
if (playerScript.sidescroller)
playerScript.sidescroller = true;
moveScript.sidescroller = true;
Player.transform.rotation = ExitCube.transform.rotation;
Player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationY;
}
}
Your answer
Follow this Question
Related Questions
Add 2D Skeleton to the Scene if Button was pressed 0 Answers
Retaining rotation (preventing rotation snapping) 0 Answers
How do i ajust the player height acording to the height of the roof in a first person game? 1 Answer
Get sprite size and position 0 Answers
How can i make my spaceship to land automatic on the Base ? 1 Answer