Search

Design To Game

Category

Workshop

How to 3D Print

UPscreenopenstarplacePrintPreviewpreferncetime

Print

Then go to print and print the model!

 

Advertisements

Useful Links

Reference Websites:

Home || Previous

HealthBar

 

Asset for Fairy Ring Games Jam

Home || Previous

Text Engine Jam

Home || Previous || Next

 

Create Text Engine Project

Screen Shot 2015-12-03 at 13.37.58.png

Create Canvas

Screen Shot 2015-12-03 at 13.38.31.png

Turn on Screen Space – Camera

Screen Shot 2015-12-03 at 13.38.57.png

You don’t normally need to change anything about the EventSystem

Screen Shot 2015-12-03 at 13.39.41.png

Add a button from the Game Object -> UI -> Button

Screen Shot 2015-12-03 at 13.42.09.png

Screen Shot 2015-12-03 at 13.45.39.png

You don’t want GUI widgets but panels so that you can position things in one go – you can do this through the parent pannel.

Delete the button and add pannel. (Game Object -> UI -> Pannel)

Screen Shot 2015-12-03 at 13.43.37.png

You can now edit and transform this, including rotating.

Screen Shot 2015-12-03 at 13.45.03.png

You can add buttons to panels.

Screen Shot 2015-12-03 at 13.47.03.png

Edit it in 2D view to see what it looks like. (Parent text to Pannel)Screen Shot 2015-12-03 at 13.56.48.png

Now make the GUI pretty:

Screen Shot 2015-12-03 at 14.14.43.png

Button has onclick events or you can write a method/function for it.

Screen Shot 2015-12-03 at 14.16.08.png

Input field has On Value Change and End Edit

Screen Shot 2015-12-03 at 14.17.54.png

And Sliders have On Value Change

Screen Shot 2015-12-03 at 14.42.58.png

Changing these menus – buttons to display text in the information text box:

Screen Shot 2015-12-03 at 14.47.15.png

Calling on Information Text found in the hierarchy: Screen Shot 2015-12-03 at 14.47.47.png

Doing the same for the other buttons, I also for the Input field change the On Value Change

Screen Shot 2015-12-03 at 14.49.02.png

This is a video of what they do:

 

Making buttons be replaces with new text

Screen Shot 2015-12-03 at 15.22.41.png

On Happy Button

Screen Shot 2015-12-03 at 15.22.52.png

 

Home || Previous || Next

 

Sharkman Codes

Home || Previous || Next

Codes for Workshop SharkMan Part 1, Part 2, Part 3,

 Test

using UnityEngine; using System.Collections;

public class Test : MonoBehaviour {

public Animation anim;

// Use this for initialization void Start () {

anim = GameObject.Find(“SharkmanFinal”).GetComponent <Animation>();

}

void TestAnim(){

//any forward input from player we move aniamtion to Swim

if((Input.GetAxis(“Vertical”) *1 * Time.deltaTime) > 0) { anim.Play(“Swim”); transform.Translate(0, 0, Input.GetAxis(“Vertical”) * 1 );

} else { anim.Play(“Idle”); } }

// Update is called once per frame void Update () {

TestAnim();

} }

Movement Script

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

public class Movement : MonoBehaviour {

public NavMeshAgent nAgent; public Vector3 desiredPosition; public List<Vector3> waypoints; public int counter; public string currentState;

// Use this for initialization void Start () {

nAgent = GetComponent<NavMeshAgent>(); waypoints = new List<Vector3>();

waypoints.Add(GameObject.Find(“WayPointOne”).transform.position); waypoints.Add(GameObject.Find(“WayPointTwo”).transform.position); waypoints.Add(GameObject.Find(“WayPointThree”).transform.position); waypoints.Add(GameObject.Find(“WayPointFour”).transform.position); counter = 0; desiredPosition = waypoints[counter];

}

void Scan() { Vector3 sharkmanPos = GameObject.Find(“SharkmanFinal”).transform.position; Debug.DrawRay(new Vector3 (sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward * 6 , Color.red); RaycastHit forwardRay;

if(Physics.Raycast(new Vector3(sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward *6, out forwardRay, 6)){ if(forwardRay.collider.tag == “Fish”){ if(GetComponent<SharkStats>().hunger >= 70){ GetComponent<StateMachine>().state = “HUNT”; } } }

} void Patrol() {

if((Mathf.Abs(transform.position.x – waypoints[counter].x) < 1) && (Mathf.Abs(transform.position.z – waypoints[counter].z) < 1)) { if(GetComponent<SharkStats>().energy >0){ GetComponent<SharkStats>().energy -= 1; }

counter += 1; if(counter == waypoints.Count) { counter = 0; } desiredPosition = waypoints[counter]; } }

// Update is called once per frame void Update () {

currentState = GetComponent<StateMachine>().state;

Scan();

if(currentState == “PATROL”) {

Patrol(); }

nAgent.SetDestination(desiredPosition);

} }

 

StateMachine

using UnityEngine; using System.Collections;

public class StateMachine : MonoBehaviour {

public string state;

// Use this for initialization void Start () {

state = “PATROL”;

}

// Update is called once per frame void Update () {

} }

Shark Stats

using UnityEngine; using System.Collections;

public class SharkStats : MonoBehaviour {

public float health; public float rage; public float hunger; public float energy;

// Use this for initialization void Start () {

health = 100f; rage = 0f; hunger = 50f; energy = 100f;

}

void increaseHunger(){

if(hunger < 100){

hunger = 100-energy; } }

void increaseRage(){

rage = hunger * 0.75f; }

// Update is called once per frame void Update () {

increaseHunger(); increaseRage();

} }

SharkmanAnimation

using UnityEngine; using System.Collections;

public class SharkmanAnimation : MonoBehaviour {

public string currentState; public Animation anim;

// Use this for initialization void Start () {

anim = GameObject.Find(“SharkmanFinal”).GetComponent<Animation>();

}

void ChangeAnimation (){

if (currentState ==”PATROL”) { anim.Play(“Swim”); } else if(currentState == “IDLE”) { anim.Play(“Idle”); }

}

// Update is called once per frame void Update () {

currentState = GetComponent<StateMachine>().state; ChangeAnimation(); } }

 

Home || Previous || Next

SharkMan Energy

Home || Previous || Next

 

Using the code and animation from previous post

 

Making Sharkman react – the more moves the hungrier he gets.

 

Under the Movement script add line 32 where the engr. lowers each time you go to a waypoint.

Screen Shot 2015-11-26 at 14.24.43.png

Also edited the Shark Stats Script:

Screen Shot 2015-11-26 at 14.30.27.png

SharkMan is getting hungrier and angrier.

 

Editing the Patrol Function (Line 32)

Screen Shot 2015-11-26 at 14.32.17.png

Write a new Function called scan and run this in update.

Screen Shot 2015-11-26 at 14.42.12.png

Debug.DrawRay(GameObject.Find(“SharkmanFinal”).transform.position, transform.forward *6 , Color.red);

Screen Shot 2015-11-26 at 14.34.22.png

to easily edit the position of the shark man the code has been put into a Vector 3 and the x,y and z is added.Screen Shot 2015-11-26 at 14.44.37.png

Vector3 sharkmanPos = GameObject.Find(“SharkmanFinal”).transform.position;
Debug.DrawRay(new Vector3 (sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward * 6 , Color.red);

Shuffle the line so it is ontop of Sharkmans head. This line just shows us where the ray casting will be – will be edited out from final code when we have the recast in place

Screen Shot 2015-11-26 at 14.46.09.png

Create a Ray Cast object, want to come from same place as the red line – so copy past line.

Screen Shot 2015-11-26 at 14.50.10.png

if(Physics.Raycast(new Vector3(sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward *6, out forwardRay, 6)){}

What type of object is it detecting “Fish”

Screen Shot 2015-11-26 at 14.51.42.png

If we see our Fish and our 70% hungry the state is change to  hunt.

Screen Shot 2015-11-26 at 15.00.47.png

void Scan() {
Vector3 sharkmanPos = GameObject.Find(“SharkmanFinal”).transform.position;
Debug.DrawRay(new Vector3 (sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward * 6 , Color.red);
RaycastHit forwardRay;

if(Physics.Raycast(new Vector3(sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward *6, out forwardRay, 6)){
if(forwardRay.collider.tag == “Fish”){
if(GetComponent<SharkStats>().hunger >= 70){
GetComponent<StateMachine>().state = “HUNT”;
}
}
}

}

 

Home || Previous || Next

 

 

 

SharkMan

Home || Previous || Next

 

Using the model we imported into Unity – see previous post

 

We now want the character to be an NPC which uses a state machine.

 

Defining the characteristics of the SharkMan:

Screen Shot 2015-11-26 at 11.14.23.png

We then set these values (if you want values to change better to start up high):

Screen Shot 2015-11-26 at 11.21.01.png

If we want hunger to go up if energy goes down (over time he gets more hunger).

Screen Shot 2015-11-26 at 11.16.24.png

We don’t want this to go over 100 as we are using this as a percentage…

Screen Shot 2015-11-26 at 11.21.50.png

The more angry SharkMan gets the hungrier he is. Rage is a given percentage of hunger e.g. you are 50% angry if you are 100% hungry. This means rage will always be 3/4 of hunger.

Screen Shot 2015-11-26 at 11.22.44.png

Remember to call the functions.

Screen Shot 2015-11-26 at 11.19.52.png

Complet Function

Screen Shot 2015-11-26 at 11.23.00.png

Add Shark Stats to Model:

Screen Shot 2015-11-26 at 11.23.37.png

 

We now want Shark Man to patrol, using way point models.

Create 3D Capsule

(the mesh render willed to be turned off later)

Screen Shot 2015-11-26 at 11.25.11.png

Place waypoints and name them

Screen Shot 2015-11-26 at 11.26.57.png

Create new script – Movement

Screen Shot 2015-11-26 at 11.27.48.png

We will need (instantiating) a Navigation Agent – called nAgent, a Vector3 position called Desired position and we need to call a list agent which we waypoints (this  will be using Vector 3)

First call the Collections. Generic in order to add lists to the code

Screen Shot 2015-11-26 at 12.28.38.png

Then institute everything… (mentioned above)

Screen Shot 2015-11-26 at 11.30.19.png

Under the start function we define nAgent and way point

Screen Shot 2015-11-26 at 11.32.29.png

Then we add the waypoints to the waypoint list

Screen Shot 2015-11-26 at 11.33.19.png

Then set the desired posion of way point to 0 as that is the start of the way point list.

Screen Shot 2015-11-26 at 11.34.09.png

We now need to add the counter and the desired Position.

Screen Shot 2015-11-26 at 12.23.07.png

Right a function for the Patrol, in order to do this we need to add a counter and a current state.

Screen Shot 2015-11-26 at 12.07.34.png

Function for Patrol

Screen Shot 2015-11-26 at 12.13.09.png

Particularly long line for the code to move between way points:

if((Mathf.Abs(transform.position.x – waypoints[counter].x) < 1) && (Mathf.Abs(transform.position.z – waypoints[counter].z) < 1)) {

You now need to add a counter and update it when the NPC has moved around all of them  – counting which one it is at.

Screen Shot 2015-11-26 at 12.20.54.png

 

Under Update, set destination to the desired position if you are moving at all.

Screen Shot 2015-11-26 at 11.40.36.png

And also reset the State Machine to the appropriate thing

Screen Shot 2015-11-26 at 12.17.27.png

 

State Machine

If the state is patrolling, run patrol algorithm, and change the state.

Screen Shot 2015-11-26 at 11.56.33.png

This will check the state machine which is to be written.

Screen Shot 2015-11-26 at 11.42.01.png

To start just add the state PATROL

Screen Shot 2015-11-26 at 12.32.25.png

 

Putting the code onto the character

Add NavMeshAgent (first you have to add a RigidBody) You might need to change some of the values for the NavMeshAgent radius so that  it fits nicely onto the character.

Screen Shot 2015-11-26 at 11.46.51.png

In order for the NavMeshAgent to work you need to go to the Navigation menu for the plane.

Set the navigation to static.

Screen Shot 2015-11-26 at 11.48.17.png

Then Bake

Screen Shot 2015-11-26 at 11.48.27.png

The waypoints need to be within the blue after Bake.

Screen Shot 2015-11-26 at 11.49.09.png

 

Add script to character.

 

 

Animation Script for animation to change on different states.

Screen Shot 2015-11-26 at 14.18.20.png

Home || Previous || Next

 

Adding Models to Unity

Home || Previous || Next

Using James Model and texture.

New Project

Screen Shot 2015-11-26 at 10.13.37.png

Add files into assets folders

Screen Shot 2015-11-26 at 10.15.18.png

Screen Shot 2015-11-26 at 10.16.10.png

Put these files into folders Textures and SharkMan

Screen Shot 2015-11-26 at 10.18.55.png

Check that the model has been imported correctly, scale factor and textures are right.

Screen Shot 2015-11-26 at 10.20.02.png

Check the Rig, this needs to be put as legacy as the animation was made in frames after one another.

Screen Shot 2015-11-26 at 10.21.55.png

The animation has been made in one long file, you can see this in the animation settings, this needs to be cut into different sections.

Screen Shot 2015-11-26 at 10.23.31.png

Shows you the different frames of the animation:

Screen Shot 2015-11-26 at 10.24.46.png

You can change the tolerances, if animation isn’t quiet right

Screen Shot 2015-11-26 at 10.27.28.png

Add more clips and add names

Screen Shot 2015-11-26 at 10.28.15.png

For Idel animation cut the clip, this should be looped

Screen Shot 2015-11-26 at 10.57.20.png

Do this for Swim and Transition (without loop) remember to apply (these needs to be in the right order…

Screen Shot 2015-11-26 at 10.37.41.png

Add model onto screen

Screen Shot 2015-11-26 at 10.35.26.png

Create C Sharp File – Test

Screen Shot 2015-11-26 at 10.39.21.png

Add public Animation anim

And add GetComponent under Start

Screen Shot 2015-11-26 at 10.48.26.png

Create new function TestAnim, which sets the animation depending on input

Screen Shot 2015-11-26 at 10.48.32.png

In void run the function

Screen Shot 2015-11-26 at 10.48.44.png

 

Make a Shark Man Controller by creating an Empty

Screen Shot 2015-11-26 at 10.52.16.png

And Parent this to SharkMan

Screen Shot 2015-11-26 at 10.52.49.png

Then in the code add GameObject.Find(“”).

Screen Shot 2015-11-26 at 10.55.31.png

To make move add a transform.Translate under the test anim.

Screen Shot 2015-11-26 at 11.00.42.png

Compete Code

Screen Shot 2015-11-26 at 11.05.35.png

In the inspector make sure Anim is linked

Screen Shot 2015-11-26 at 11.05.15.png

HE swims backwards so needs to be flipped 180

Screen Shot 2015-11-26 at 11.07.10.png

 

Home || Previous || Next

 

 

 

 

 

 

Navigation Workshop

Home || Previous || Next

Creating an NPC which finds a player

  1. Create a 3D Project in Unity
  2. Create Plane (world)
  3. Create cubes (Wall)
  4. Select all and make staticScreen Shot 2015-11-19 at 10.24.12.png
  5. Go to navigation windowScreen Shot 2015-11-19 at 10.26.02.png
  6. Select the world – Click Bake Screen Shot 2015-11-19 at 10.27.10.png
  7. Create cube and call in NPC which needs a rigid body and Navmesh agent.Screen Shot 2015-11-19 at 10.30.42.png
  8. Nav Mesh Agent changes the way the NPC moves: base offset moves the characters height, stopping distance is another good one to change.
  9. Create a cylinder and call it Player, add tag of player.Screen Shot 2015-11-19 at 10.34.55.png
  10. Create script – Pathfinder in c SharpScreen Shot 2015-11-19 at 10.36.51.png
  11. Define Game Object and set it to Player. Then Define NavMesh Agent and attache it to the NavMesh AgentScreen Shot 2015-11-19 at 10.40.15.png
  12. Set the naavMeshAgent to the players transform position (this requires a Vector3)Screen Shot 2015-11-19 at 10.42.30.png
  13. Add the script to NPC thus allowing it to navigate to player.Screen Shot 2015-11-19 at 10.44.21.png
  14. Change stopping distance to stop the NPC pushing the player.

Creating a NPC which patrols

  1. Getting the NPC to patrol
  2. Create objects with no meshScreen Shot 2015-11-19 at 10.49.26.png
  3. The NPC will still find the object
  4. You could have multiple of these objects and use an array to call them in order.
  5. Creating a patrolling npc

 

Understanding the A* Principle

AStarAlgo.jpg

 

Home || Previous || Next

Blog at WordPress.com.

Up ↑