Tag Info

Hot answers tagged

4

You can Destroy the component. Be careful about which object you destroy, though. If you pass a GameObject to Destroy, you will destroy the entire thing. To destroy the component, you must pass a reference to that component specifically. //example: destroys the MeshRenderer attached to this GameObject var sphereMesh = GetComponent(MeshRenderer); ...


3

Rather than hard-coding your data in Javascript, why not use JSON. It's always a good idea to separate your data from your program, and splitting out item definitions into JSON files would be very clean I think. Node even let's you use "require" with JSON files, how handy: How to parse JSON with node Databases are a great technology to learn if you haven't ...


2

EDIT (added short steps): get triangle normal vector v1 (normalized) get reference surface normal vector v2 (normalized) get angle between normals : angle = acos(v1•v2) (where • = 'dot' product ) get slope = Tan(angle) if you need a surface normal here come the simple algoritm : A surface normal for a triangle can be calculated by taking the vector ...


2

One way to apply light effects with the Context2D is to use the composite operation 'lighter' (globalCompositeOperation='ligther'), and adjust the alpha (globalAlpha= 0.0 to 1.0). Then you can either : • Draw the shape of the light with several geometric drawings that create a simple shade to get a cartoonish light effect. • Define gradients to get a ...


2

Since javascript is a scripting language, updating it wouldn't be a big deal, it would mean restarting the server, but it would seem most online games go through some sort of restart when introducing new things anyways. You really don't want this. Yes, some items will need reboots, because they'll need new accompanying game logic. Minor updates, ...


1

I solved it! A friend of mine told me it's pretty standard if the material is not set to doublesided. (Or I could make a billboard out of it). But in code I had to add mat.side = Three.DoubleSide; Sorry guys for bothering you with this - it was probably quite basic but I'll leave it on just in case someone else encounters this problem!


1

To make it easier for you to switch between world coordinates and grid coordinates, you should make two functions, projectToWorld and projectToGrid. pseudo code: /** * returns the topleft position of a given grid coordinate. */ function projectToWorld(gridX, gridY) { return new Vector2(TILE_WIDTH * gridY, TILE_HEIGHT * gridY); } /** * ...


1

You don't necessarily need a parabola formula for this. The best way, in my opinion, to do this is to update the velocity of the ball each frame. I don't know how you organized your code, but I assume you have an update function that is executed multiples times per frame. To make the trajectory of a parabola, you simply need to substract a constant to the ...


1

Hey there are couple of things which you are missing out. 1) Even thought the motion is in 2d plane but the gameobject dimension is 3D, so use Vector3 instead of Vector2 2) When you calculate Vector3 Movetowards it returns a value which is calculated upon current position , target position and speed. This needs to be assigned to the transform of the AI. ...


1

Make sure that "Is Kinematic" option for rigidbody in the inspector is off. Here is a very basic example for adding torque. var torque: float; var rigidBody: Rigidbody2D; function Start() { torque = 20; rigidBody = GetComponent.<Rigidbody2D>(); } function FixedUpdate() { rigidBody.AddTorque(Time.deltaTime*torque); } Time.delta time ...


1

As Vector2 is a type composed by two numbers which are x and y, then you should be able to get the position by asking both numbers: Vector2 YourVar; YourVar.x; YourVar.y; So you should use something like: SetPositionToMove(YourVar.x,YourVar.y); //if the functions expect x and y or: SetPositionToMove(Point2(YourVar.x,YourVar.y)); //if it expects a ...


1

Refactoring is your friend !!! Separate the issues and try to get your code as generic as possible. Separate and factorise the steps of the computing. Keep comments short. • Boilerplate : // ------------------------ var g = 9.81; //Gravitational acceleration var v = 35.9; //Experimantally measured arrow speed var sqrt = Math.sqrt, atan2 = ...



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