





I created a flow chart for the two enemy script alex asked me to do. When touched by a weapon(shape like a stick), one minion will have its head pop off and the other will disappear and be replaced with items.
The scene is set up with a 2 box(player and enemy). Player will have a stick while the enemy will have a head. My first problem I ran into was learning how to get the collider to work. Which was hard because no one knew what every part of the collider script do so I figured out what can general used for set it up with the enemy. Problem is, I don't know how to script an actual collision script or contactPpoint script. After mind numbing reading and researching, OnTrigger script seem to work best if not easiest for me.
After I set up a collider box for the enemy, I inputed
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "weapon") {
print ("hit")
}
}
That script above will print out "hit" in the debug log so I know it works. Now I have to script the head so it will pick up the hit.
function Update (){
if (playerHit == true){
rigidbody.transform.Translate(Vector3.up * 10 * Time.deltaTime);
}
}
If didn't make the head pop and I couldn't figure out why. I realized the problem was the player hit that the collider script is picking up, isn't being picked up by the head script. I couldn't figured it out right away but I found out that I have to make the variable able to be picked up from other scripts. I ran across a script where someone was using static var so I hope that was it
static var playerHit = false;
that still didn't work. I realized after reading the console that I have to specify where the variable is coming from
in the collider script
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "weapon") {
print ("hit")
enemyHead.playerHit = true;
}
}
In this script I have to state that the playerHit is from the enemyHead script.
With those scripts in place, everything works except the head won't stop floating. I tried adjusting the gravity but ended up messing with the game physics and everything was affected by it. Spent hours on unity3d and no one could pin point the problem or how to work with the gravity specifically for the object. It then occur to me that the jump script in the fps walker does exactly what I needed. I asked Robin if he could help me created and we both looked over the walker script to see what we can learn from it. Robin came up with a script for me that didn't work for me for some reason so I used and wrote my own script from what I learned and able to get the head to pop up and drop. Now the problem is it bounces up and down, non stop.
I added
private var moveDirection = Vector3.zero;
and placed
moveDirection.y -= gravity * Time.deltaTime;
in the update function. this script will need refining for it to work smoothly.
Now I have the enemy replace, item drop script to work on. I used most of the same scene and some of the scripts with some modification. Now understanding how to do this is easy, knowing the scripts to use is a whole different story. Based on my past experience with Unity Script, I have to instantiate an object with the object I want to replace. Prefabbing which was easy.
Same problem I had with the gravity script and moving script, no where tells you the exact function of every part of the script so you know what needs to be replaced and so on.
After researching for an hour, I learned that when instantiating, you will need to var the objects you want to make reference to.
var object1 : GameObject
var object2 : GameObject
*I've seen some put Transform instead of game object with im baffled about.
the instantiate script is
Instantiate(object you want to create, object you want to replace(transform), object you want to replace rotation(rotation);
that script should instantiate for you.
I created a script and collider for the body. With my new understanding how instantiate works.
I set the body script to instantiate the prefab in its location and then destroy itself, revealing the drop item.
var poops : GameObject;
var enemy : gameObject;
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "weapon"){
Instantiate(poops, enemy.transform.position, enemy.transform.rotation);
Destroy(enemy);
}
}
And that script should work.
I am in charge of working on the minion script. My task was to get the minion flying, hover around the character, and be able to maneuver. It has been awhile that I actually sat down and scripted in unity so it took me some time to figure out what scripts was needed.
I started by using the FPS walker script that has been prefab’d in unity.
-------------------------------
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
----------------------------------
As I was trying to read the script, I had to look up on what some of functions were doing like FixedUpdate() which I found out that its like the regular FixedUpdate but should only be used for rigid bodies. for what the bodies starts adding force, it will count/update for every fixed frame of it.
To simplify the character controller script to use for the minion. I established the keyboard speed with var keyboardSpeed = 50; testing the script at this speed was too fast so I brought it down to 1.
From there I added function
FixedUpdate()
{
Var keyboardX = Input.GetAxis(“Horizontal”) * keyboardSpeed * Time.deltaTime;
//The script line above stats the default settings for moving on the X axis is set to default keys and run on the set keyboard speed and smoothly per frame. I completed with the rest of the moving lines:
Var keyboardZ = Input.GetAxis(“Vertical”) * keyboardSpeed * Time.deltaTime;
Var keyboardY = Input.GetKey(“Space”) * keyboardSpeed * Time.deltaTime;
//The jump script above had to be set to the default jump settings until I can figure out a more specific and manual way of scripting the jump. The script line for jump didn’t work and I had to figure out a fix which I did later.
var newPos = rigidbody.position + Vector3(keyboardX, keyboardY, keyboardZ);
//take the current rigidbody position + the changed(added) axis changes from key inputs = newPos
rigidbody.MovePosition(newPos);
//take the newPos coordinates and move the rigidbody to that location
}
@script RequireComponent(Rigidbody)
I used unity3d to look up script and reference.
The jump was tricky for me to get working and I wasn’t completely sure if we were going to use the jump but I figured I could always mod the script later to do a ascend and descend. The jump had to set its y variable and assigned an input. I couldn’t get it right, right away. I was getting a input script error for that script line. After talking to rob about it, he told me about the default jump that’s in unity.
I just had to add a variable at the top
Var Jump
Then change
Input.GetKey(“Space”)
To
Input.GetAxis(“Jump”)
Jump is the default setting for jump in unity and it works for now but the gravity is applied to the character which restricts the floating/hovering that Alex wants.
I didn’t do any programming. I just did research on things from the list: animals, basket, design (motif, patterns etc), some general stuff, monuments, plants, pottery, some rituals, statues, tools and weapons. Searching for stuff like plants and animals was difficult because you have to find out the name for most of them in order to get more result for them. Tools was spread out. There were tools for crafting, farming, rituals and so on.