Here is my individual journal, along with all of the code that I have done.
Tuesday, 4 November 2014
Tuesday, 9 September 2014
2D Character Controller Improvements
I spent today improving my 2D character controller from yesterday.
I have now coded a way for the player to pick up a certain power-up that lets them destroy objects in the scene.
I have also stopped the issue that made the character 'stick' to walls if a directional button was being pressed by creating a 2D Physic Material that gives the character 0 friction while he is not grounded.
I have fine tuned the punch/attack script to allow the punches to use 2d Colliders and 2D Rigidbodies without interacting with the player. I did this by making the actual colliders only cover the very front of the attack instantiation.
I also successfully recreated my climbing script from the default Unity Character Controller. I reduced the complexity of the code as well.
I have now coded a way for the player to pick up a certain power-up that lets them destroy objects in the scene.
I have also stopped the issue that made the character 'stick' to walls if a directional button was being pressed by creating a 2D Physic Material that gives the character 0 friction while he is not grounded.
I have fine tuned the punch/attack script to allow the punches to use 2d Colliders and 2D Rigidbodies without interacting with the player. I did this by making the actual colliders only cover the very front of the attack instantiation.
I also successfully recreated my climbing script from the default Unity Character Controller. I reduced the complexity of the code as well.
Sunday, 7 September 2014
Character Movement for 2D
I have created a new controller for the character. I have made this new controller so it will interact better in a 2D environment. Previously I used the default Unity Character Controller to control the character. While this worked for a while it soon became apparent that it was not optimized for a 2D platformer.
Tuesday, 26 August 2014
CodeVoidUpdate
void Update () {
UpdateCamera ();
theSpriteScale = transform.localScale;
if (Input.GetKeyDown(KeyCode.LeftArrow)|| Input.GetKeyDown(KeyCode.A))
{
spriteFaceRight = false;
spriteFaceLeft = true;
}
if (Input.GetKeyDown(KeyCode.RightArrow)||Input.GetKeyDown(KeyCode.D))
{
spriteFaceLeft = false;
spriteFaceRight = true;
}
if (spriteFLeftLock)
{
spriteFaceLeft = false;
print("leftLock");
}
if (spriteFRightLock)
{
spriteFaceRight = false;
print ("rightLock");
}
if (spriteFaceLeft)
{
theSpriteScale.x *= -1;
transform.localScale = theSpriteScale;
spriteFLeftLock = true;
spriteFRightLock = false;
spriteFaceLeft = false;
print ("spriteFaceLeft");
}
if (spriteFaceRight)
{
theSpriteScale.x *= -1;
transform.localScale = theSpriteScale;
spriteFRightLock = true;
spriteFLeftLock = false;
spriteFaceRight = false;
print("spriteFaceRight");
}
if ((Character_Controller.collisionFlags & CollisionFlags.Sides) == 0)
{
isClimb = false;
}
if (cactusPower == true) {
if ((Character_Controller.collisionFlags & CollisionFlags.Sides) != 0)
{
isClimb = true;
}
if (isClimb == true) {
if (Input.GetKey(KeyCode.LeftArrow)|| Input.GetKeyDown(KeyCode.A))
{
faceRight = false;
faceLeft = true;
}
if (Input.GetKey(KeyCode.RightArrow)|| Input.GetKeyDown(KeyCode.D))
{
faceLeft = false;
faceRight = true;
}
gravity = 0.0f;
climbDir = new Vector3 (0, Input.GetAxis ("Vertical"), 0);
climbDir = transform.TransformDirection (climbDir);
climbDir *= climbSpeed;
print ("climbing=true");
Character_Controller.Move (climbDir * Time.deltaTime);
if (Input.GetButtonDown ("Horizontal"))
{
if ((Time.time - lastTapTime) < doubleTapTime)
{
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, 0);
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= Speed;
print ("doubletap");
isClimb = false;
}
lastTapTime = Time.time;
}
}
if(faceLeft == true)
{
if (Input.GetButtonDown ("Jump"))
{
climbDir = new Vector3 (1, 0, 0);
climbDir = transform.TransformDirection (climbDir);
climbDir *= jumpOffSpeed;
print ("jumpLeft");
}
}
if(faceRight ==true)
{
if (Input.GetButtonDown ("Jump"))
{
climbDir = new Vector3 (1, 0, 0);
climbDir = transform.TransformDirection (climbDir);
climbDir *= jumpOffSpeed;
print("jumpRight");
}
}
}
if (isClimb == false)
{
if (Character_Controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"),0,0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= Speed;
this.drift ();
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
if (GameObject.FindWithTag("PunchHand") != null) //this will stop more punches happening
{
print("allowpunchfalse");
allowPunch = 0;
}
if (GameObject.FindWithTag("PunchHand") == null)
{
print("allowpunchtrue");
allowPunch = 1;
}
if (allowPunch == 1)
{
Rigidbody2D clone;
if (Input.GetKey(KeyCode.LeftArrow)|| Input.GetKeyDown(KeyCode.A))
{
faceRight = false;
faceLeft = true;
}
if (Input.GetKey(KeyCode.RightArrow)|| Input.GetKeyDown(KeyCode.D))
{
faceLeft = false;
faceRight = true;
}
if (faceLeft == true)
{
if (Input.GetButtonDown("Punch"))
{
print("faceLeftTrue");
clone = Instantiate(spawnSpriteLeft, transform.position, transform.rotation) as Rigidbody2D;
clone.velocity = transform.TransformDirection(Vector3.forward * 10);
/*float punchmovement = Time.deltaTime *punchprojSpeed;
transform.Translate(-punchmovement,0,0);
Destroy (spawnSpriteLeft, punchlifetime);*/
}
}
if (faceRight == true)
{
if (Input.GetButtonDown("Punch"))
{
print("faceRightTrue");
clone = Instantiate(spawnSpriteRight, transform.position, transform.rotation) as Rigidbody2D;
clone.velocity = transform.TransformDirection(Vector3.forward * 10);
/*float punchmovement = Time.deltaTime *punchprojSpeed;
transform.Translate(punchmovement,0,0);
Destroy (spawnSpriteRight, punchlifetime);*/
}
}
}
gravity = setGravity;
print("climbing=false");
moveDirection.y -= gravity * Time.deltaTime;
}
Character_Controller.Move (moveDirection * Time.deltaTime);
}
UpdateCamera ();
theSpriteScale = transform.localScale;
if (Input.GetKeyDown(KeyCode.LeftArrow)|| Input.GetKeyDown(KeyCode.A))
{
spriteFaceRight = false;
spriteFaceLeft = true;
}
if (Input.GetKeyDown(KeyCode.RightArrow)||Input.GetKeyDown(KeyCode.D))
{
spriteFaceLeft = false;
spriteFaceRight = true;
}
if (spriteFLeftLock)
{
spriteFaceLeft = false;
print("leftLock");
}
if (spriteFRightLock)
{
spriteFaceRight = false;
print ("rightLock");
}
if (spriteFaceLeft)
{
theSpriteScale.x *= -1;
transform.localScale = theSpriteScale;
spriteFLeftLock = true;
spriteFRightLock = false;
spriteFaceLeft = false;
print ("spriteFaceLeft");
}
if (spriteFaceRight)
{
theSpriteScale.x *= -1;
transform.localScale = theSpriteScale;
spriteFRightLock = true;
spriteFLeftLock = false;
spriteFaceRight = false;
print("spriteFaceRight");
}
if ((Character_Controller.collisionFlags & CollisionFlags.Sides) == 0)
{
isClimb = false;
}
if (cactusPower == true) {
if ((Character_Controller.collisionFlags & CollisionFlags.Sides) != 0)
{
isClimb = true;
}
if (isClimb == true) {
if (Input.GetKey(KeyCode.LeftArrow)|| Input.GetKeyDown(KeyCode.A))
{
faceRight = false;
faceLeft = true;
}
if (Input.GetKey(KeyCode.RightArrow)|| Input.GetKeyDown(KeyCode.D))
{
faceLeft = false;
faceRight = true;
}
gravity = 0.0f;
climbDir = new Vector3 (0, Input.GetAxis ("Vertical"), 0);
climbDir = transform.TransformDirection (climbDir);
climbDir *= climbSpeed;
print ("climbing=true");
Character_Controller.Move (climbDir * Time.deltaTime);
if (Input.GetButtonDown ("Horizontal"))
{
if ((Time.time - lastTapTime) < doubleTapTime)
{
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, 0);
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= Speed;
print ("doubletap");
isClimb = false;
}
lastTapTime = Time.time;
}
}
if(faceLeft == true)
{
if (Input.GetButtonDown ("Jump"))
{
climbDir = new Vector3 (1, 0, 0);
climbDir = transform.TransformDirection (climbDir);
climbDir *= jumpOffSpeed;
print ("jumpLeft");
}
}
if(faceRight ==true)
{
if (Input.GetButtonDown ("Jump"))
{
climbDir = new Vector3 (1, 0, 0);
climbDir = transform.TransformDirection (climbDir);
climbDir *= jumpOffSpeed;
print("jumpRight");
}
}
}
if (isClimb == false)
{
if (Character_Controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"),0,0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= Speed;
this.drift ();
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
if (GameObject.FindWithTag("PunchHand") != null) //this will stop more punches happening
{
print("allowpunchfalse");
allowPunch = 0;
}
if (GameObject.FindWithTag("PunchHand") == null)
{
print("allowpunchtrue");
allowPunch = 1;
}
if (allowPunch == 1)
{
Rigidbody2D clone;
if (Input.GetKey(KeyCode.LeftArrow)|| Input.GetKeyDown(KeyCode.A))
{
faceRight = false;
faceLeft = true;
}
if (Input.GetKey(KeyCode.RightArrow)|| Input.GetKeyDown(KeyCode.D))
{
faceLeft = false;
faceRight = true;
}
if (faceLeft == true)
{
if (Input.GetButtonDown("Punch"))
{
print("faceLeftTrue");
clone = Instantiate(spawnSpriteLeft, transform.position, transform.rotation) as Rigidbody2D;
clone.velocity = transform.TransformDirection(Vector3.forward * 10);
/*float punchmovement = Time.deltaTime *punchprojSpeed;
transform.Translate(-punchmovement,0,0);
Destroy (spawnSpriteLeft, punchlifetime);*/
}
}
if (faceRight == true)
{
if (Input.GetButtonDown("Punch"))
{
print("faceRightTrue");
clone = Instantiate(spawnSpriteRight, transform.position, transform.rotation) as Rigidbody2D;
clone.velocity = transform.TransformDirection(Vector3.forward * 10);
/*float punchmovement = Time.deltaTime *punchprojSpeed;
transform.Translate(punchmovement,0,0);
Destroy (spawnSpriteRight, punchlifetime);*/
}
}
}
gravity = setGravity;
print("climbing=false");
moveDirection.y -= gravity * Time.deltaTime;
}
Character_Controller.Move (moveDirection * Time.deltaTime);
}
Monday, 25 August 2014
Sunday, 24 August 2014
Starting New Task
I will now be using this blog to document my progress with the development of Frost Fall
Subscribe to:
Posts (Atom)






