Hot answers tagged

15 votes
Accepted

How to randomly place entities that don't overlap?

A Poisson-Disk sampling distribution will allow you to select random points a minimum distance apart. Your situation is similar to this question, but since your trees aren't idealized points you'll ...
user avatar
  • 8,530
4 votes

How to structure code for many unique weapons/spells/powers

Data-Driven Design I submitted something like this question to code review recently. After some suggestions and improvements, the result was a simple code that would allow some relative flexibility ...
user avatar
4 votes
Accepted

Retrieve the original prefab from a game object

Simple Answer Use a class to load the original prefab from Resources.Load(string prefabPath, typeof(GameObject)); Store this returned prefab into a resource pool ...
user avatar
3 votes
Accepted

Change parent object on instantiation

For me it should be done in this way: What we need: A throw point - a Transform attached to mode's palm of hand Throw animation (Option A ) A event that will be fired during the throw animation, at ...
user avatar
  • 455
3 votes
Accepted

Unity2D: Vector3.Lerp - smooth movement

Before I go into the code, I want to go over how Lerp works. Vector3.Lerp(Vector3 start,Vector3 end, float fraction); The above code will return a Vector3 that ...
user avatar
  • 46
2 votes
Accepted

Space between randomly generated objects

You can split this into two stages: Firstly generate some pinecones with such minimum distance between them that you need: On second stage add some pinecones next to those placed already: That way ...
user avatar
  • 10k
2 votes
Accepted

Rendering order for units behind objects?

You need to enable some kind of z-buffering: first render unobstructed units, then buildings, then units that are obstructed (complete or just partially) by buildings and then the ground. If you ...
user avatar
  • 453
2 votes
Accepted

A logic error. canvas: balls physics, bounce

To figure out what is going on, I started looking at the code that moves the balls. In this case it is physics (fisicas). I see ...
user avatar
  • 17.9k
2 votes

Tree of objects in 2D space - children relative to parent

With transform hierarchies (trees), the normal method is to work your way up or down the tree, applying any transformations of the parent to the child, at each level, till you have processed ...
user avatar
  • 29.1k
2 votes
Accepted

Evenly distribution of 2 or more shapes given their x and y points inside a bounding box

If you have a set of bounding boxes and the first and last one shouldn't get moved, then you can create a line out of the center points of these two and line the ither center points up with it. So, ...
user avatar
  • 14.5k
2 votes

How to have random and different colors on multiple objects with one material?

You can change the color of the same material, on different objects, from script. Do the following: Create a materialand assign it to the target game object. Create a new C# script, and copy in the ...
user avatar
2 votes
Accepted

C++ create array of multiple types

When you have an array of type Entity then you can only call methods on the entries which are declared in the class Entity. If ...
user avatar
  • 111k
2 votes

Can a character interact well with surroundings in-game?

Yes. This is all doable. Limitations in games most of the time come from features being too heavy for the physics engine ("we can't simulate that many bodies at once, otherwise it trashed the ...
user avatar
  • 15.3k
2 votes
Accepted

Calculate coordinates of boundaries containing group of objects

This is a broad question, so a broad answer is required. You can follow up individual implementations / algorithms yourself, and post separate questions if you need to. The basic approach for games ...
user avatar
  • 29.1k
2 votes
Accepted

Painter's theorem inside and outside test

I'm not familiar with the exact situation being discussed here — it's been a while since I've worked with plane equations — but in general, much of the math in computer graphics has opportunities to ...
user avatar
  • 4,379
1 vote

C++ Instantiating objects as function arguments / parameters (base and derived classes)

1) Not certain polymorphism works unless it is a pointer/reference parameter, it might be the case that the base-class part of your derived class is just cut and pasted into the argument , "slicing" ...
user avatar
  • 135
1 vote

Change parent object on instantiation

This is the code I used to make the shoot of the grenade. It works, but now, I'm thinking when I need to destroy the object on collision, is possible that I will need to put de newShoot variable out ...
user avatar
  • 117
1 vote

Equal objects with independent variables in Game Maker?

There are many ways to do it. For example: obj_runner Create ...
user avatar
  • 1,040
1 vote

LIBGDX - group as child of an actor?

We don't know which things are containers and what they can contain. But let's assume your world work this way: Empires can contains Kingdoms, but also Cities (which are not contained by any ...
user avatar
1 vote
Accepted

Difference between Object.Destroy() and GameObject.Destroy() in Unity

None. GameObject.Destroy() is inherited from Object.Destroy(). Both statements refer to the same method. This is not explicitly ...
user avatar
  • 2,034
1 vote

Make character move behind object

This is one of the main reasons why we don't use tiles for objects, like trees. Sprites are much easier to manage. Anyhow, most engines, frameworks and APIs allow you to render the sprites based on a ...
user avatar
  • 14.5k
1 vote

How to detect when object A In point B place

Unless you're running on extremely slow hardware or dealing with incredibly fast objects, checking per-frame should be fine as long as you aren't looking for an exact hit. It's best to check the ...
user avatar
1 vote
Accepted

How to prevent clicking through object in GameMaker

You could check in obj_gameover whether the ball is clicked too or not. Something like: Left Pressed (obj_gameover): ...
user avatar
1 vote

Identify objects of the same type from each other, even between game restarts?

I would suggest using GUID - it is widely used and pretty much every language/lib has an implementation, python included. A common practice is to express it as hexadecimal string, possibly also ...
user avatar
  • 4,870
1 vote
Accepted

How do I pass my objects to the update method?

As long as all of your mentioned methods are in the same class, you do not need to pass your objects to the methods - if you just declare your objects in that class. That is the normal way to do it. ...
user avatar
  • 406
1 vote
Accepted

Design Pattern for "Default Object"

http://en.wikipedia.org/wiki/Flyweight_pattern is the pattern name if I'm reading your question correctly.
user avatar
  • 251
1 vote
Accepted

I can't drag'n'drop UI-Elements from the Scene-hierarchy into a public field (Unity 5)

Instead of creating a regular game object, create a UI Image ( New >> UI >> Image/slider/etc.). The new Unity UI system has specifics that aren't available to normal game objects, so when you make ...
user avatar
1 vote
Accepted

Is it possible to control what script is active on what sprite/object in Unity?

It would be better to add a bool variable into your Script and then toggle it on/off. ...
user avatar
1 vote
Accepted

Help with understanding "transform.root.GetComponent<>" in Unity

I am not quite sure what you are not understanding here, but I attempt to answer your question anyway. I am not quite getting what that does or what purpose it serves. In cases where you do not ...
user avatar
  • 3,162

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