Flying Pig

Anyways for this project ideally I’d want to take the joke literally. So as for the game:

Well basically you – the flying pig – are flying through the skies minding your own business while laying… golden eggs… on people’s houses come under attack by the military who are trying to stop your tyranny – mostly the eggs you ally that crush their houses.

Idea is a point based system based on number of structures destroyed before being shot down and special bonus for passing through the level unharmed. The higher the level the more rockets and other types of enemy objects would come at you (i.e. planes, bombs from the sky, turrets below).

Probably be a score leaderboard as well. Co-op and versus too if it was taken far.

Here’s the ground from following along. It will need to be decorated a bit.

The very compounded Fpig.

Haha, awesome

FPig makes some enemies - might have eaten too much.

Sweeeeet model. Flying pigs are tight!

For the next stage tried spawning some moving enemies.

(extra force from the golds gives Fpig a bit too much of an advantage)

1 Like

made some changes - don’t now if this will load

Flying Pig takes to the sky to find the pumpkin field the army has launched into the air, only the rockets are having some trouble making it difficult for the meal to be reached without getting smacked.

(little longer than 15 seconds but feel free to skip through - I played with the oscillator code a bit)

1 Like

That landing pad is death is sweet! Love the humor!!

Thanks. At first I was just oscillating between set rotations, but that felt a bit too controlled – at least I think that’s what it is :stuck_out_tongue_winking_eye:. Still need to learn a bit more about quaternions really.

1 Like

Post your quaternion code if you don’t mind. I’d like to see it and possibly make crazy things happen in my game too :slight_smile:

1 Like

Here it is below – I might be a mess, so if there is a better format for uploading feel free to ping.

I used the basic oscillator they taught and did a duplicate bit for the rotation. I commented out the controlled oscillation between two points for my code.

Function: private void OscRotation()

I also did some code to get obstacles to move in local space on one of my levels as an option in the movement oscillator.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[DisallowMultipleComponent]
public class Oscillator : MonoBehaviour
{

[SerializeField] Vector3 movementVector = new Vector3 (10.0f, 10.0f, 10.0f);
[SerializeField] float period = 2.0f;
[Range(0, 1)] float movementFactor;
[SerializeField] Vector3 startingPostion; //must be stored for absolute movement
//[SerializeField] Vector3 endingPosition;


[SerializeField] Vector3 rotationVector = new Vector3(0.0f, 0.0f, 0.0f);
[SerializeField] float rotationPeriod;
[Range(0, 1)] float rotationFactor;
[SerializeField] Quaternion startingRotation;


[SerializeField] Boolean isLocal = false;

// Start is called before the first frame update
void Start()
{
    startingPostion = transform.position;
    startingRotation = transform.rotation;
}

// Update is called once per frame
void Update()
{
    Movement();
    OscRotation();

}

private void OscRotation()
{
    //set movement factor
    if (rotationPeriod <= Mathf.Epsilon)
    {
        return;
    }
    float cycles = Time.time / rotationPeriod; //grows continually from 0

    const float tau = Mathf.PI * 2;
    float rawSinWave = Mathf.Sin(cycles * tau);

    rotationFactor = rawSinWave / 2 + 0.5f;

    Vector3 offset = rotationFactor * rotationVector;
    //transform.rotation = Quaternion.Euler(offset); //this was the controlled version osscilating between two points
    transform.Rotate(offset); //this here cause the rotations to become out of control; however, if you run it you will notice there are points where the rotation slows down before winding back up -- I believe at the end of the sin waves

}

private void Movement()
{
    //set movement factor
    if (period <= Mathf.Epsilon)
    {
        return;
    }

    float cycles = Time.time / period; //grows continually from 0

    const float tau = Mathf.PI * 2;
    float rawSinWave = Mathf.Sin(cycles * tau);

    movementFactor = rawSinWave / 2 + 0.5f;

    Vector3 offset = movementVector * movementFactor;

    if (!isLocal)
    {
        transform.position = startingPostion + offset;
    }
    else
    {
        transform.position = startingPostion + transform.TransformDirection(offset);  // wanted to create the option to move the object according to the local axis
    }

         
    //transform.Translate(startingPostion + offset, Space.Self);
}

}

Privacy & Terms