Its just too hard!

At Uni we’ve been told to make a simple retro 2d game. I can do all the art and visual stuff fine, but when it comes to scripting i just go into meltdown. All i need my character to do, is move around and jump. But when i look at javascript i just don’t understand any of it, its so confusing with all the different symbols like ‘{ , :, ;, =’ and names "transform, vector, float, deltatime’

I’ve managed to make my character move around by using script taken from one of the basic scripting tutorials. But every tutorial i find pretty much says, do this, copy this, paste this and wallah! It doesn’t explain what stuff actually does. For my movement so far i have this :

var speed = 5.0;
function Update () {

var x = Input.GetAxis(“Horizontal”) * Time.deltaTime * speed;
var y = Input.GetAxis(“Vertical”) * Time.deltaTime * speed;
transform.Translate (x,y,0);
}

How on earth do i add to this script so my character jumps? I wouldn’t know how to do this, let alone make the character collide with things properly, change direction facing when moving left and right ect. I thought id add a screenshot of the scene so you can get a better idea of what I’m talking about, basically you’re a little rabbit that has to collect carrots. Cheers for any help.


i suggest opening up the unity scripting reference :slight_smile: look at basic scripts and when you get to a function or something you don’t understand look at the reference :slight_smile: you can get to the reference under the help menu inside of Unity. If you don’t know the syntax (the “grammar”) than that’s a different story and i suggest you look up some “UnityScript” tutorials :slight_smile:

Good luck!
why789

P.S. programming is hard :wink: if you are only interested in making 2d games than I suggest Game Maker (www.yoyogames.com) It is much easier to learn its code if you don’t know any coding whatsoever (like i was) and it doesn’t have many 3d options (the reason why im here :smile:)
Game Maker is basically easier if all you want to do is make 2D games, if you are interested in 3D than Unity blows Game Maker and any other engine ive seen far far away :slight_smile:

Sadly… I was just working on a simple Character controller with a WoW camera controller. The script minus the Camera part. I added in the one piece that would turn the 3rd person into a top down character controller. (a look at in the direction you are moving)

// WowCharacter.cs
using UnityEngine;
using System.Collections;

public class WowCharacter : MonoBehaviour {
	bool isPlayer = true;
	
	private float speed = 5.0f;
	private float jumpSpeed = 8.0f;
	private float gravity = 20.0f;
	private Vector3 moveDirection = Vector3.zero;

	
	// Use this for initialization
	void Start () {
		CharacterController controller = gameObject.GetComponent<CharacterController>();
		if(controller == null){
			controller = gameObject.AddComponent<CharacterController>();
		}
	}
	// Update is called once per frame
	void Update (){
		CharacterController controller = GetComponent<CharacterController>();
		if (controller.isGrounded) {
			moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
			moveDirection = transform.TransformDirection(moveDirection);
			moveDirection *= speed;
			if(moveDirection.magnitude > 0.0f)transform.LookAt(transform.position + moveDirection);
			if (Input.GetButton("Jump"))
				moveDirection.y = jumpSpeed;
		}
		moveDirection.y -= gravity * Time.deltaTime;
		controller.Move(moveDirection * Time.deltaTime);
	}
}

Its written in C# but if Javascript looks alien so will this. Throw it on a basic capsule and move around the world. :wink:

Here is a great resource if you want to learn UnityScript: http://www.unityscript.com/lessons1/basics.php
This is excellent trening course that will definitely teach you how to script: http://www.walkerboystudio.com/html/unity_training___free__.html

Learn Programming with this excellent guide for kids: Visual Studio Express | Now Visual Studio Community
Give it a shot, the language is actually C# but that does not matter until part 3/4.

Good luck on your Endeavor.

Thanks for the help guys, ill start looking through these resources !

these guys doing a great video tutorial series

good luck !

Programming is not exactly hard, what is hard is learning how built in functions work with little to no explanation on the science of the application of it. Delta Time Severely has halted my game design so I’m afraid i’m going to have to learn unreal.

Who necroes a 2011 thread?

3 Likes

You know Unreal has deltaTime too?

2 Likes

I think all games have a deltaTime of some sort (since Doom?).
Thats because the code has to run the same way on all CPU archictectures.

Also, read the manual. Unity has a Scripting API manual that is more or less decent for understanding.

You only need to use delta time if you want movement and animation etc. to be framerate independent, it’s not essential to make use of it. If it’s confusing while learning just ignore it until you are at the point you can make sense of how it’s used.