Exemplo n.º 1
0
 private void Start()
 {
     _player     = FindObjectOfType <PlayerController>();
     _boomTarget = new GameObject("Boom Target");
     _boomTarget.transform.SetParent(this.transform);
     _boom = FindObjectOfType <CameraBoom>(); // <-- Gross!
 }
Exemplo n.º 2
0
        // Constructor called when creating or loading an object
        protected TP_ThirdPersonMonoCharacter(ObjectInitializer initializer)
            : base(initializer)
        {
            // Set size for collision capsule
            CapsuleComponent.SetCapsuleSize(42.0f, 96.0f);

            // set our turn rates for input
            BaseTurnRate   = 45.0f;
            BaseLookUpRate = 45.0f;

            // Rotate the camera with the controller, not the character.
            UseControllerRotationPitch = false;
            UseControllerRotationYaw   = false;
            UseControllerRotationRoll  = false;

            // Configure character movement
            CharacterMovement.OrientRotationToMovement = true;                            // Character moves in the direction of input...
            CharacterMovement.RotationRate             = new Rotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
            CharacterMovement.JumpZVelocity            = 600.0f;
            CharacterMovement.AirControl = 0.2f;

            // Create a camera boom (pulls in towards the player if there is a collision)
            CameraBoom = initializer.CreateDefaultSubobject <SpringArmComponent> ("CameraBoom");
            CameraBoom.SetupAttachment(RootComponent);
            CameraBoom.TargetArmLength        = 300.0f;      // The camera follows at this distance behind the character
            CameraBoom.UsePawnControlRotation = true;        // Rotate the arm based on the controller

            // Create a follow camera
            FollowCamera = initializer.CreateDefaultSubobject <CameraComponent> ("FollowCamera");
            FollowCamera.SetupAttachment(CameraBoom, SpringArmComponent.SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
            FollowCamera.UsePawnControlRotation = false;                             // Camera does not rotate relative to arm

            // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
            // are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C#)
        }
Exemplo n.º 3
0
        public override void Initialize(FObjectInitializer initializer)
        {
            base.Initialize(initializer);

            UCharacterMovementComponent characterMovement = CharacterMovement;
            UCapsuleComponent           capsuleComponent  = CapsuleComponent;

            // Use only Yaw from the controller and ignore the rest of the rotation.
            UseControllerRotationPitch = false;
            UseControllerRotationYaw   = true;
            UseControllerRotationRoll  = false;

            // Set the size of our collision capsule.
            capsuleComponent.SetCapsuleHalfHeight(96.0f);
            capsuleComponent.SetCapsuleRadius(40.0f);

            // Create a camera boom attached to the root (capsule)
            CameraBoom = initializer.CreateDefaultSubobject <USpringArmComponent>(this, (FName)"CameraBoom");
            CameraBoom.SetupAttachment(RootComponent);
            CameraBoom.TargetArmLength  = 500.0f;
            CameraBoom.SocketOffset     = new FVector(0.0f, 0.0f, 75.0f);
            CameraBoom.AbsoluteRotation = true;
            CameraBoom.DoCollisionTest  = false;
            CameraBoom.RelativeRotation = new FRotator(0.0f, -90.0f, 0.0f);

            // Create an orthographic camera (no perspective) and attach it to the boom
            SideViewCameraComponent = initializer.CreateDefaultSubobject <UCameraComponent>(this, (FName)"SideViewCamera");
            SideViewCameraComponent.ProjectionMode = ECameraProjectionMode.Orthographic;
            SideViewCameraComponent.OrthoWidth     = 2048.0f;
            SideViewCameraComponent.SetupAttachment(CameraBoom, USpringArmComponent.SocketName);

            // Prevent all automatic rotation behavior on the camera, character, and camera component
            CameraBoom.AbsoluteRotation = true;
            SideViewCameraComponent.UsePawnControlRotation = false;
            SideViewCameraComponent.AutoActivate           = true;
            characterMovement.OrientRotationToMovement     = false;

            // Configure character movement
            characterMovement.GravityScale   = 2.0f;
            characterMovement.AirControl     = 0.80f;
            characterMovement.JumpZVelocity  = 1000.0f;
            characterMovement.GroundFriction = 3.0f;
            characterMovement.MaxWalkSpeed   = 600.0f;
            characterMovement.MaxFlySpeed    = 600.0f;

            // Lock character motion onto the XZ plane, so the character can't move in or out of the screen
            characterMovement.ConstrainToPlane = true;
            characterMovement.SetPlaneConstraintNormal(new FVector(0.0f, -1.0f, 0.0f));

            // Behave like a traditional 2D platformer character, with a flat bottom instead of a curved capsule bottom
            // Note: This can cause a little floating when going up inclines; you can choose the tradeoff between better
            // behavior on the edge of a ledge versus inclines by setting this to true or false
            characterMovement.UseFlatBaseForFloorChecks = true;

            // Enable replication on the Sprite component so animations show up when networked
            Sprite.SetIsReplicated(true);
            Replicates = true;
        }
Exemplo n.º 4
0
 private void Mechanism_Activated(Mechanism mechanism)
 {
     if (_boom == null)
     {
         _boom = FindObjectOfType <CameraBoom>(); // <-- Gross!
     }
     _previousBoomTarget = _boom.Target;
     _boom.Target        = _moveTarget;
     StartCoroutine(MoveBack()); // <-- Also Gross!
     Time.timeScale = 0;
 }
Exemplo n.º 5
0
    public void Init()
    {
        islandCount             = 0;
        transform.localPosition = Vector3.zero;
        if (islands.Count > 0)
        {
            foreach (Island island in islands)
            {
                if (island != null)
                {
                    CameraBoom boom = island.GetComponentInChildren <CameraBoom>();
                    if (boom != null)
                    {
                        boom.transform.parent = null;
                    }
                    DestroyImmediate(island.gameObject);
                }
            }
            islands.Clear();
        }
        int r = random.Next(5) + 2;

        for (int i = 0; i < r; i++)
        {
            islands.Add(CreateIsland());
        }
        FindObjectOfType <CameraBoom>().attachedObject = islands[0].gameObject;
        if (sunMesh != null)
        {
            DestroyImmediate(sunMesh.gameObject);
        }
        sunMesh = CreateMesh();
        LineRenderer line      = GetComponent <LineRenderer>();
        int          vertCount = 1;
        float        radius    = 110f;
        float        x;
        float        y;
        float        h = -2f;

        for (float i = 0; i < 2 * Mathf.PI; i += 0.05f)
        {
            x = radius * Mathf.Cos(i);
            y = radius * Mathf.Sin(i);
            line.SetVertexCount(vertCount++);
            line.SetPosition(vertCount - 2, new Vector3(x, h, y));
        }
        line.SetVertexCount(vertCount++);
        x = radius * Mathf.Cos(0);
        y = radius * Mathf.Sin(0);
        line.SetPosition(vertCount - 2, new Vector3(x, h, y));
    }
Exemplo n.º 6
0
    private void Start()
    {
        fadeTexture.color = new Color(fadeTexture.color.r, fadeTexture.color.g, fadeTexture.color.b, 0);
        mainCam           = Camera.main.gameObject.transform;
        boom = mainCam.GetComponent <CameraBoom>();

        //Initialize starting character
        switch (startingCharacter)
        {
        case Entity.Human:
            ChangeTo(human);
            break;

        case Entity.Dog:
            ChangeTo(dog);
            break;
        }
    }
Exemplo n.º 7
0
    private void Start()
    {
        fadeTexture.color = new Color(fadeTexture.color.r, fadeTexture.color.g, fadeTexture.color.b, 0);
        mainCam = Camera.main.gameObject.transform;
        boom = mainCam.GetComponent<CameraBoom>();

        //Initialize starting character
        switch (startingCharacter)
        {
            case Entity.Human:
                ChangeTo(human);
                break;
            case Entity.Dog:
                ChangeTo(dog);
                break;
        }
    }