Tag Info

Hot answers tagged

27

You need to take the sum of the directions, normalize that, then multiply by the speed. I tangentially answered this as part of my response to Preventing diagonal movement Specifically: velX = 0; velY = 0; if(keyLeft) velX += -1; if(keyRight) velX += 1; if(keyUp) velY += -1; if(keyDown) velY += 1; // Normalize to prevent high speed diagonals length = ...


12

Separate your direction selection code from actual movement code. Choose Direction by checking which keys are pressed. Store it as a unit (normalized) vector. Multiply your Direction with Speed and with DeltaTime. Apply resulting transform to your object/camera.


11

The "normalized direction vector" is how this task is usually approached, and how I often do it, but lately I've simply been clamping the resulting movement vector. It usually achieves the same end result and the code is a lot simpler: var moveSpeed = 6.0f; function Update() { var movement = Vector3.zero; movement.x = Input.GetAxis("Horizontal") * ...


3

First off, if you are that new to Unity, maybe you would benefit a lot from going through tutorials. Unity website has some pretty handy tutorials, plus some nice step-by-step complete projects. Nevertheless I´m going to give you a general answer to guide you with your question. For my answer I assume you are familiar with some basic Unity3D concepts, as ...


3

Here is my suggestions Dealing with Trees You can do any tree by using tables. It can serve as dependency counter for what ever tree you are doing. Already tested by me some time ago were skill tree, knowledge tree and my favorite, item tree. For this example we are going to use "Item" tree. Each item will be a record for the table name ItemTree. They ...


2

Your error is on these lines if(healthbar!=0){ healthbar-=30; Because 500 is not divisible by 30, you get something like this: 50, 20, -10, -30... What you really mean is if(healthbar>0){ healthbar-=30; Because you want to decrease if it is bigger than 0, not if it is different than 0 (very important distinction!). Also, in order to make ...


2

Check out colliders. You'd likely want to implement OnCollisionEnter in your character class. When something collides with the player, this method will be activated. Inside this method is where you'll deduct from the player's health. If the player can only collide with one thing (the sphere objects), you can make it pretty simple: function ...


2

The HTML5 canvas works... well... like a canvas. It is a collection of RGBA pixels. When you draw something, it replaces whatever was there before. There is no "undo" functionality. The usual approach is what you are doing right now: start each rendering frame by completely erasing the canvas and redrawing the whole scene from scratch. When you have lots ...


1

From the screens it's kinda obvious, that your tiles are positioned wrong. So it seems your X axis needs to go from top-left to bottom-right and Y axis from top-right to bottom-left. Right now X goes from left to right and Y from top to bottom. Can you update your code to accommodate for that? Also your spacing between the tiles is too big, but first - ...


1

It's really your tools' responsibility to respond appropriately to events, so I'd recommend representing each of your tools as an object containing functions that handle mouse events and delegating the event handling to the currently active tool. In practice, you can do this by defining your tools var railsTool = { onMouseUp : function(event) { /* ...


1

You should specify clearly what you are trying to accomplish. You speak about progress bar but use a playerEnergy variable. Are you trying to fill or to deplete the bar? In any case this line looks suspicious. playerEnergy=Time.time *0.02; This line has two potential problems (that we cannot state properly until we know exactly what you want to do). The ...


1

In your second if you access the pillar and you set it to an object. When you try to access the pillar-Object, it never has been set and as such is initialized with null. This is your error. //first if { tempPillar = GameObject.FindGameobjectWithTag ("Pillars"); //second if with tempPillar! { pillar =tempPillar; //play ...


1

You are only checking to see if healthbar is not zero (if(healthbar!=0)), you should rather check if it is greater than 0, like so: if(healthbar>0) { //Do something } But it might be easier to check if it is less than or equal to zero, so that you can use it to end the game easier, like so: if(healthbar <= 0) { EndGame(); } else { ...


1

It might be related to your Update function: function Update() { if (triggered && Input.GetKeyDown(KeyCode.JoystickButton1)) particle1.SetActive(true); particle2.SetActive(true); particle3.SetActive(true); } Having no brackets, only particle1.setActive(true) is in the condition. The other two will be called on each ...


1

I agree with Oliver Schöning's response. I haven't used ImpactJS before, so I'll talk about C2: C2 pros: Very well documented. Many tutorials. Dedicated plugins: Platformer games become very easy to develop. The SDK is extensible with your own plugins and behaviors. C2 cons: To integrate some third party plugin in your game (e.g. Socket.io) you must ...



Only top voted, non community-wiki answers of a minimum length are eligible