Build 3D objects in-game?

Started by
8 comments, last by Sleicreider 8 years, 9 months ago
I would like to know if this techique has a name and how it works:
I saw it in several games, where object are automatically aligned near other objects to build a house or whatever.
can anynone help me?
Advertisement
There are some assets in Unity that can do that.

I don't know if it has a name, but it looks like the game is determining possible locations for whatever item type is selected and then just casting a ray from the cursor and highlighting the indicated position.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

It looks to me that the world in this game is built of an invisible cube-based grid.

When you click the mouse cursor, a ray is projected from the current view plane until it hits the first cube plane of the grid, and where it hits, it projects the 'ghost' box to hint at where it might place the item.

Each item has a weight and mass and is a physics object, in this case in UE4 it would be PhysX. These physics objects can be placed and have enough mass to support each other and the player. I'm guessing here, but i'd do this and not use kinematic objects to allow the player to later destroy their construction using weapons or by dropping things onto it (think like angry birds).

Something like this would probably take an hour or so to make in UE4, probably a bit longer if you werent using a pre-made engine.

There's a couple concepts at work, most of which are independent and not all of which have one name.

The overall idea is called "placing objects at runtime." The concept of having objects aligned to nearby objects by default when placing them is called "snapping" or "automatic alignment" or some variation thereof. The technique for determining where in the 3D world the 2D cursor or focal point is looking at is called "picking."

Implementing these algorithms is a broad topic; there's no one way to do so. It largely depends on the information and tools you have available in the codebase or engine you're using, and the shape of your data.

well i'm working with ue4, but don't really know where to start.

also searched about alignment and snapping, but haven't found much

What have you tried?

Can you perform the first thing shown in that video, looking at a spot and dynamically spawning some object where you're looking with a keypress? If not, consider focusing only on that problem first.

yup i know how to do that :P


Can you perform the first thing shown in that video, looking at a spot and dynamically spawning some object where you're looking with a keypress? If not, consider focusing only on that problem first.


yup i know how to do that

so you take the x,z position you'd place the object at, integer divide x and z by 10, then multiply x and z by 10, and just like that you're snapping to 10x10 grids.

IE: raypick returns coordinates 127,38. integer divide by 10 yields 12,3. multiply by 10 yields 120,30. so you picked 127,38, but snap to 120,30.

then its just setting the orientation (y rotation). axis aligning everything is one easy way to handle this. IE y rotation = 0, and make sure your models face the correct direction in your modeling software before export.

that's the general approach that first comes to mind.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php


Can you perform the first thing shown in that video, looking at a spot and dynamically spawning some object where you're looking with a keypress? If not, consider focusing only on that problem first.


yup i know how to do that

so you take the x,z position you'd place the object at, integer divide x and z by 10, then multiply x and z by 10, and just like that you're snapping to 10x10 grids.

IE: raypick returns coordinates 127,38. integer divide by 10 yields 12,3. multiply by 10 yields 120,30. so you picked 127,38, but snap to 120,30.

then its just setting the orientation (y rotation). axis aligning everything is one easy way to handle this. IE y rotation = 0, and make sure your models face the correct direction in your modeling software before export.

that's the general approach that first comes to mind.

this seems to be a good solution :) i'll try it as fast as possible

This topic is closed to new replies.

Advertisement