Friday, March 31, 2017

I can't fix this

I wrote two scripts for movement one for computer input to test the game in unity and one for mobile devices those scripts are making the same things but the first one uses computer's keyboard and the second one uses touches. For two days I am trying to figure out what is wrong with my mobile script. Walk animation that I prepared before is played in unity (on computer), but when I am trying to launch it on my phone the animation (that should be only played when I am walking). The animation doesn't work at all. Here are these scripts:

ComputerController

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

public class ComputerController : MonoBehaviour {
   // Use this for initialization
    void Start()
    {
        animator = GetComponent<Animator>();
        rb = GetComponent<Rigidbody2D>();
    }
    bool facingRight = true;
    public int speed;
    public Animator animator;
    public Rigidbody2D rb;
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.D))
        {
            if (facingRight)
            {
                transform.Translate(speed * Time.deltaTime, 0, 0);
            }
            else Flip();
        }

        if (Input.GetKey(KeyCode.A))
        {
            if (!facingRight)
            {
                transform.Translate(-speed * Time.deltaTime, 0, 0);
            }
            else Flip();
        }
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
        {
            animator.SetBool("IsWalking", true);
        }else animator.SetBool("IsWalking", false);

        if (Input.GetKey(KeyCode.Space))
        {
            rb.AddForce(new Vector3(0, 1, 0), ForceMode2D.Impulse);
        }
    }

    void Flip()
    {
        facingRight = !facingRight;
        Vector3 theScale = transform.localScale;
        theScale.x *= -1;
        transform.localScale = theScale;
    }
}


TouchController

"using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;

public class TouchControler : MonoBehaviour{
    // Use this for initialization
    void Start()
    {
        animator = GetComponent<Animator>();
        rb = GetComponent<Rigidbody2D>();
    }
    bool facingRight = true;
    public int speed;
    public Animator animator;
    public Rigidbody2D rb;
    public Vector2 position;
    // Update is called once per frame
    void Update()
    {
        if (Input.GetTouch(0).position.x > position.x)
        {
            if (facingRight)
            {
                transform.Translate(speed * Time.deltaTime, 0, 0);
            }
            else Flip();
        }
        if (Input.GetTouch(0).position.x < position.x)
        {
            if (!facingRight)
            {
                transform.Translate(-speed * Time.deltaTime, 0, 0);
            }
            else Flip();
        }
        if (Input.GetTouch(0).phase == TouchPhase.Moved|| Input.GetTouch(0).phase == TouchPhase.Stationary)
        {
            animator.SetBool("IsWalking", true);
        }else animator.SetBool("IsWalking", false);

        if (Input.GetTouch(1).phase == TouchPhase.Began)
        {
            rb.AddForce(new Vector3(0, 5, 0), ForceMode2D.Impulse);
        }
        if (Input.GetTouch(2).phase == TouchPhase.Began)
        {
            SceneManager.LoadScene("scene");
        }
    }

    void Flip()
    {
        facingRight = !facingRight;
        Vector3 theScale = transform.localScale;
        theScale.x *= -1;
        transform.localScale = theScale;
    }
}
"

Saturday, March 25, 2017

Making our character jump.

Today comes the time when our inquisitor will jump for the first time. So let's define our input.
If we touch the screen with 2nd finger our character will jump.

First let's add Rigidbody 2D component from our inspector window.
  

Now open our previously created movement script add add a new public Rigidbody2D variable:

public Rigidbody2D rb;

Add it to our class but don't put it to any of functions inside it.

Now assign our Rigidbody2D component created in "Inspector" window to previously created variable. Put our code inside Start function.

 rb = GetComponent<Rigidbody2D>();

Now create a force that will push our sprite up when we touch the screen with the 2nd finger:
 
if (Input.GetTouch(1).phase == TouchPhase.Began)
        {
            rb.AddForce(new Vector3(0, 10, 0), ForceMode2D.Impulse);
        }


Put it inside Update function to check every frame if the screen has been touched.
GetTouch(1) means the 2nd finger because we are starting counting from 0 and if 2nd finger touched (Began) the screen this if statement is equal to truth.



Movement script for Unity

First of all let our character move left and right. We will make it funny, our character will go left when we have one finger on the screen, and will go right if this finger in moving on the screen.

To do so create a C# script and in our "Update" function write:

if (Input.GetTouch(0).phase == TouchPhase.Stationary)
        {
            transform.Translate(1 * Time.deltaTime, 0, 0);
        }


This code means that every frame (in Update function) the game will check if you have at least one finger on the screen (the first one, that touched the screen counts) and if that finger isn't moving (TouchPhase.Stationary). If it is so our object (that we will attach our script later) will go 1*Time.deltaTime in x axe. Here we are using Time.deltaTime because it allows us to get the same movement speed if we have 30 FPS, 60 FPS and any other*.

Now write:

if (Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            transform.Translate(-1 * Time.deltaTime, 0, 0);
        }


 It is same as above but instead of 1 we have -1 to get the movement in opposite direction.

Now the only thing to do is to drag our script from "Assets" window in Unity and drop it on our object. To be sure if our script is attached click the object and open ""Inspector" window.

As you can see i have attached "New Behavior Script 1" script to my object.





*because Time.deltaTime is called every frame and Time.deltaTime is the duration of our frame.That allows us to have constant movement speed since frames per second times duration of a frame is always the same.

Saturday, March 18, 2017

Switching to Unity

 QUICK INFO


Unreal Engine 4 is not an easy engine, and I have to say that this project pinned me down. It was even worse than I thought, that it will be, because of low 2D C++ support from Epic Games in their game engine. The breakthrough was the moment when Artur Dębkowski (click) wrote a comment under my post about programming in Unreal Engine. I didn't want to learn from basics again but it seems like I will have to start "Faith The Beginning" from the beginning (kill me for that joke).

So Nintendo started selling Switch and I am switching to Unity (I am not joking kill me).

Monday, March 13, 2017

Introduction to programming in Unreal Engine 4 part 2

If you followed my previous post about programming in Unreal Engine you surely has created a camera and static mesh component, that are attached to root component. Now we are gonna "learn our character to move and jump".

1. We will need to change input settings in unreal editor, so go to "Edit" and then "Project Settings",
 
2. Now go to "Engine" and "Input",
 3. And set "Bindings" like on the picture.



First of all let's create few variables and functions in our header file:

"void Move(float value);
void DoJump();
FVector ActorLocation;
UPROPERTY(EditAnywhere)
USceneComponent* VisibleComponent;
FVector CurrentVelocity;"

We will need them later.
Now we should declare our input in SetupInputPlayerComponent function. To do so write:

"InputComponent->BindAxis("Move", this, &AMainCharacter::Move);
InputComponent->BindAction("Jump", IE_Pressed, this, &AMainCharacter::DoJump);"

And now our DoJump and Move functions declarations.

"void AMainCharacter::Move(float value)
{
         CurrentVelocity.X = FMath::Clamp ( value, 1.0f, -1.0f)* 100.0f;
}
void AMainCharacter::DoJump()
{
         CurrentVelocity.Z = 1000.0f;
}"

Now comes the most important thing we need to let our player to move over time (every tick).
So let's write in our "Tick" function:

"ActorLocation = GetActorLocation();
if(!CurrentVelocity.IsZero))
{
           FVector NewLocation = ActorLocation + (CurrentVelocity * DeltaTime);
           SetActorLocation (NewLocation);
}
if (CurrentVelocity.Z > 0.0f || CurrentVelocity < 0.0f || CurrentVelocity.Z == 0.0f && ActorLocation.Z >=0.0f)
{
           CurrentVelocity.Z -= 100.0f;
}
if (ActorLocation.Z <=0.0f)
{
           CurrentVelocity.Z = 0.0f
}"

  1. Now if we press space the DoJump function will be called and will set our main character's velocity to 1000.
  2. After every tick will lose 100 velocity until it's speed will be bigger than 0.
  3. Then it's velocity will be equal to  0 and and it will be higher than 0 so it will start to get minus velocity and it will start falling.
  4. Then it will still fall because our velocity will be lower than 0.
  5. Until it hits the 0 height (so our ground).

Sunday, March 12, 2017

First sprites

 Yesterday I went to my friend Michał Tuliszkiewicz, he is a very good drawer and he has recently bought a graphic tablet. With my idea, his skill and his experience we have created the inquisitor's sprite, and started one background. He finished this background later and drawn additionally demon's sprite. Great thanks to Michał for his hard work and help, we will surely meet each other to prepare more sprites and background.













Meanwhile I am still learning on examples how to code in Unreal Engine 4, I don't know enough to code without getting on a problem. For example today I couldn't attach a sprite to my "MainCharacter" pawn and couldn't set it to movable. I hope to solve them quickly and learn something from these problems. Progression is satisfactory but expectations are high. Keep your fingers crossed for me.


Thursday, March 9, 2017

Introduction to programming in Unreal Engine 4 part 1

As some of you might know to write a code in Unreal Engine we use C++. But it is not as simple as just C++. There are many functions and classes that are already made to communicate with Unreal Engine editor. Most of people use only blueprints in UE4 but I am taking part in a programming competition, I have to write at least some code for my game's logic instead of blueprints.
So I started reading documentation of UE4. I was like "That is too much", "Why I have to do this here". But after these several days I think that I finally understand something. So here I will try to explain how to make our main character jumping and walking (and also falling and stopping on the ground)


So lets begin. First of all we will need to create a new pawn class.








We will name it "MainCharacter".










Now we need to create a new root component to be able to attach to it rest of our components.
So we have to add:

"RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));"

to our AMainCharacter constructor in cpp file. And now we can attach our camera and our static mesh components to root component. So first of all let's create them.
Write:

"VisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisibleComponent"));
 UCameraComponent* Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
"

 and don't forget to define our VisibleComponent, to do this write

"UPROPERTY(EditAnywhere)
USceneComponent* VisibleComponent;"

UPROPERTY(EditAnywhere) will allow us to add our custom static mesh in Unreal Editor and under this line we will define VisibleComponent as a USceneComponent (don't write a semicolone after UPROPERTY).

Now we are ready to attach them:

"Camera->SetupAttachment(RootComponent);
  Camera->SetRelativeRotation(FRotator(0.0f, -90.0f, 0.0f));
  Camera->SetRelativeLocation(FVector(0.0f, 250.0f, 100.0f));
"

We just attached our new created camera to our RootComponent, then turned it through an angle of -90° in Y and moved it 250 units in Y and 100 units in Z (so up) relatively to RootComponent.

Now if we compile it in our Unreal Editor and drag in our viewport we will see something like this.



To find out more visit the 2nd part.



Friday, March 3, 2017

Main concepts

And finally came the time for the first post about my game. I was inspired by Jacek Piekara's books about inquisitor named Mordimer Madderdin. First of all I wanted to make a game about Christ, that has came down from the cross (exactly as it is in the book's universe), but then I realized, that it is too much for me, and I am not able to make such a big 3D game. I gave up with games. I tried to learn something about making websites in HTML with CSS and JavaScript (with some JQuery). Then I heard from Mateusz Kupilas known also as JavaDevMatt, that Maciej Aniserowicz is organizing a programming competition. I decided to take part in it just for myself. I am not thinking about winning in this competition, but just about finishing my project and learning more about real programming in projects bigger that a 50 lines (console program).

First concept art of my Christ game made by my friend

And here are my assumptions:
  1. 2D (I am not ready for a 3D game yet),
  2. Main character will have dark side (idk how big it will be),
  3. Sprites will be hand-drawn (I know a good drawer and it will be funny to do these with him),
  4. The game will be similar to, a platform games,
  5. Music will be composed by me. 
I am hope, that all of them will be accomplished more or less.
Subscribe my RSS channel: click
Have a nice day ;)

Thursday, March 2, 2017

ReSharperC++ licence for contestants


I saw yesterday, that Piotr Wandycz published on his blog (click), that he wrote to JetBrains with request for ReSharper for contestants (more details and license here). He succeed, I wrote a comment under his post asking about the C++ version of this program. Piotr replied and asked for contact. After consultation with Piotr I wrote to JetBrains for ReSharper C++ license and ....... I succeed.
I got a multi user evaluation key for 2 months. I was happy about it and I wrote to Maciej Aniserowicz with request for help with informing other contestants. Now the most important part.

How can I get ReSharper C++?


  1. Write to me an e-mail : wachowiakf@gmail.com
  2. Download ReSharper C++  click
  3. Open Visual Studio
  4.  You will see the window, that is above the list.
  5. Now click the plus to add Licence Key
  6. And select license key that I sent you (like on window under the text)
  7. Click "Add" and close
  8. Congratulations now you can use ReSharper C++ (2 months only)
GL&HF in your projects
If you want to see more of my posts subscribe :  RSS
Thanks to JetBrains for supporting competition "Daj Się Poznać"

Wednesday, March 1, 2017

It's time to begin, isn't it?

Hi, I was waiting for this day since I've found out that Maciej Aniserowicz is organising a competition named "Daj Się Poznać", that's also the reason why I established this blog. I hope that it will give me a lot of fun and I won't stop writing it after this competition.

Now something about my project. I'm going to make a platform game for Android devices, and "making" is not a coincidence here. I used make because my programming skills are not prepared for such a big project. I know that I will be proud of myself when I will finish it. I am so excited about making these sprites, music, and story. And at the same time I hope that by writing code for my Unreal Engine 4 actors I will expand my knowlege and programming skill. It will be hard, but it is worth my time.

I know that I will find some time to write posts here and start making my game, but sadly I'm not sure if I will finish it in time. That's because of school lessons (sometimes till 5p.m.) tests, shorttests etc..
Also right after Easter I will have to worry about Middle school tests. Luckily I'm a laureate of physics competition, that gives me free entry to whatever high school I want.

If you want to see more of my posts subscribe :  RSS

Greate thanks to Maciej Aniserowicz for organising such a big competition, only announcement motivated me so much, that I decided in a moment to take part in it.

Check out also his blog (in Polish) : Devstyle