Minecraft like building system

0

Has anyone tried making a building system like minecraft using lua? Basically I just need to figure out how to get the world translation of the collision hit from a raycast so I can attach a brick spawner to it....then figure out how to get them to either snap to grid or each other...I was able to achieve the first part with script canvas, but have had no luck with lua yet...I have been looking hard for at least some kind of sample code that could achieve this but...no luck.

已提問 6 年前檢視次數 178 次
35 個答案
0
已接受的答案

That is Amazing.

已回答 6 年前
0

Here's my guess on how to set a snaping block. But I'm almost certain its wrong the way I wrote the vectors and positions but what your trying to do is similar to this I'm sure you'll understand. Also Here is how to spawn a Block based on position of ray hit.

REMOVEDUPLOAD

已回答 6 年前
0

This is in response to your previous question where you where trying to get the position of the rayHit. I'm not sure if this is right completely what you asked but. This is what I did in my fps Gun script where I used a ray to get the entity that had a enamy tag. It may have some information you need. I also posted information on how to get its hit world position.

REMOVEDUPLOAD

已回答 6 年前
0

@REDACTEDUSER

That's looking pretty awesome, how far do you plan on taking it? I imagine that you will make roof pieces, stair pieces, fences, and other parts. Did you also make a UI for selecting the pieces that you are placing into your level?

已回答 6 年前
0

Here is what I eventually came up with. It works pretty well. On the snapping, I rounded the x,y,z separately. I used a variable (roundto) to allow different variations of snapping for different structures...like wall vs foundation...
I went ahead and gave up on the simple mindcraft building system...because it seemed a bit cheesy. This system allows for multiple types of building structures...
The one thing I seem to be having issues with...is simply destroying a misplaced slice. ---onpressed-------------------------
if buildMode == true and
current_bus == self.fightBusId then
SpawnerComponentRequestBus.Event.Spawn(self.Properties.ghostFoundation)
end
if buildMode == true and
current_bus == self.fightBusId then
SpawnerComponentRequestBus.Event.Spawn(self.Properties.ghostWall)
end if buildMode == true and
current_bus == self.rollBusId then
TransformBus.Event.RotateAroundLocalZ(self.Properties.ghostWall, (pi * .5))
end
---onheld----------------------------------------
if current_bus == self.oneBusId then
buildMode = true
xroundto=.5
zroundto=4
yroundto=.5
TransformBus.Event.SetLocalZ(self.Properties.cam_z, 2)
TransformBus.Event.SetLocalY(self.Properties.cam_z, 1)
TransformBus.Event.SetLocalX(self.Properties.cam_z, 0)
TransformBus.Event.SetWorldTranslation(self.Properties.ghostFoundation, buildLoc)
end
if current_bus == self.twoBusId then
buildMode = true
xroundto=1
zroundto=4
yroundto=1
TransformBus.Event.SetLocalZ(self.Properties.cam_z, 2)
TransformBus.Event.SetLocalY(self.Properties.cam_z, 1)
TransformBus.Event.SetLocalX(self.Properties.cam_z, 0)
TransformBus.Event.SetWorldTranslation(self.Properties.ghostWall, buildLoc)
end ----building system
if buildMode == true then
local build = RayCastConfiguration()
local camPosition = TransformBus.Event.GetWorldTM(self.Properties.cam_y)
local mask = PhysicalEntityTypes.Static + PhysicalEntityTypes.Terrain;
build.origin = camPosition:GetPosition()
build.direction = camPosition:GetColumn(1);
build.maxDistance = 50;
build.physicalEntityTypes = mask
local result = PhysicsSystemRequestBus.Broadcast.RayCast(build)
local count = result:GetHitCount()
if count > 0 then
local hit = result:GetHit(1)
buildHit = hit.position
spawnedBlock = hit.entityId
Debug.Log(tostring(spawnedBlock))
--	xroundto=.5
--	zroundto=4
--	yroundto=.5
if buildHit.x*xroundto<0 then x=-.5 else x=.5 end
Integer, decimal = math.modf(buildHit.x*xroundto+x)
xx = Integer/xroundto if buildHit.y*yroundto<0 then x=-.5 else x=.5 end
Integer, decimal = math.modf(buildHit.y*yroundto+x)
yy = Integer/yroundto if buildHit.z*zroundto<0 then x=-.5 else x=.5 end
Integer, decimal = math.modf(buildHit.z*zroundto+x)
zz = Integer/zroundto buildLoc = Vector3(xx,yy,zz)
Debug.Log(tostring(buildLoc)) end
已回答 6 年前
0

Hey, I made a little video of the building system in action.

https://youtu.be/UMbVlW0h9bY

已回答 6 年前
0

Awesome, I think that is the only thing I didn't try. I will check it oue when I get home.

已回答 6 年前
0

To completion hopefully. My kiddos and I love survival games and I'm having a blast trying to figure out how to make one. Once I get all these systems working, it will just be a matter of adding content. The kids are learning how to use blender so it should be interesting. My secondary goal is to post everything I do and learn to make it easier for others to learn and maybe take interest in this awesome game engine. I have tinkered a bit with unity and unreal...but found the workflow mind-numbing...so here I am...still a noob...but finding lumberyard extremely easy to learn.

已回答 6 年前
0

Well ya saved me again.. Thanks!

I couldn't wait to get home to try so I went through remote desktop.

已回答 6 年前
0

I'm glad it worked

已回答 6 年前
0

The UI and inventory are next on the agenda.

已回答 6 年前
0

I'm not sure if this is what you trying to do, but if you still need it this is a way to destroy a slice you created using the raycasthit. This may help.

REMOVEDUPLOAD

已回答 6 年前
0

Thanks, I actually saw this last night but figured it was out-dated...I will check it out again tonight.

已回答 6 年前
0

Awesome, I was able to use the second method to track stats like stamina and health. The first method requires that I get a reference from the receiving script. The problem I ran into is that I didn't know how to get a reference of my character's script into the uicanvas script. The methods are different for getting references. I am probably missing something simple.

已回答 6 年前
0

You refrence it by makeing a property variable that holds a entity id. Then in the editor drag the entity that is holding the receiving message script into the slot. This method works by entity id to refrence a certain entity. There is an example of how its done in the sending message script. You put the property of what entity you want to send the script then the key then the data type.

已回答 6 年前
0

Hate to keep bugging you, but I seem to have hit another road-block on something that looks like it should be simple.'

I got the building system working smoothly.

  1. press b to go into build mode

  2. press 1-4 to select building structure

  3. use mouse wheel to rotate structure

  4. press left mouse button to spawn.

The ui canvas seems easy enough to setup, however getting my canvas lua script to communicate with the main lua script seems daunting. I'm sure there is an easy way to do it, but I haven't found much info on it. I'm afraid some of the info I have found so far is out dated.

Anyway, all i want to do is use the newest lua ui commands to simply bring up and make the ui interactable with the mouse then have the selections select the building structure instead of just number keys.

...pressing b goes into build mode and allows you to mouse-select from equipped row ui.

i have made some progress on enabling mouse and bringing up ui's, but no communication between scripts.

已回答 6 年前
0

Please please make tutorials. Would help everyone trying to learn the engine. Also you r right the link i gave you that is not best example. I will show u best way later on. But if you have questions ask me I pretty much know most of the info in making games in lua in lumberyard. :D more people learning the engine makes it better.

已回答 6 年前
0

Ill be home around 11:00

已回答 6 年前
0

Also i liked your video can you make more :D. Your wip is amazing.

已回答 6 年前
0

I plan on making many more...

If I ever get good enough, I might try to make a few tutorials. Right now most of my time on this is spent just hunting for info on how to resolve seemingly simple little problems that pop up. I really think they should have a guy whose job is to spend 8 hours a day writing sample code demonstrating the engine's capabilities and creating tutorials. That's the best way to draw people in imo.

已回答 6 年前
0

How to I drag a reference from my main character to the character properties reference on this UI Canvas? Or do I not need to do that to send info from the ui to the main character?REMOVEDUPLOAD

已回答 6 年前
0

If I want to send info from the uicanvas script to the main character script do I need to reference the main character script in the uicanvas script? If so, I don't see a way to do that. I replied with a screenshot of what I was referring to over the weekend but it got deleted twice for some reason..

已回答 6 年前
0

But in the script that receives the message the entity is set to self.

已回答 6 年前
0

The data u sent is sent to the on event begin function

已回答 6 年前
0

Example where it says info

已回答 6 年前
0

How do I drag my character to the character reference slot on the right? Or do I not need that to be able to send info to my character?REMOVEDUPLOADdesktop-screenshot-20180721-23185045.png

已回答 6 年前
0

no. It is different then unity and unreal you are unable to reference like example UIScript().variable = 10. << this cannot be done. You have to rely on Ebuses.

已回答 6 年前
0

again, my screenshot was deleted

已回答 6 年前
0

Scroll down close to the bottom of the tutorials section in this link where it sais how to interact with ui in lua. This is the link to the page: https://gamedev.amazon.com/forums/tutorials

已回答 6 年前
0

I apologize I thought you already new about that stuff so i thought you where talking about something else. I hope thats what you where looking for.

已回答 6 年前
0

lol...i posted this 2 days ago and it just came through.

已回答 6 年前
0

no worries..i meant the image showed up in the post 2 days later...maybe they had to review it or something...

已回答 6 年前
0

@REDACTEDUSER

已回答 6 年前
0

I created an example of how it is used so you can see how it is done and used.

https://forums.awsgametech.com/t/how-to-make-health-pickup-in-lua/5568/1

已回答 6 年前

此貼文已關閉:已停用新增新答案、評論和投票功能。