Pancakes Posted March 21, 2010 Share Posted March 21, 2010 Hello, I'm getting my first lua scripting by messing around with Josh's Bullet.lua I have some experience with Python and javascript but sometimes I'm an idiot. It would help me a lot if I could get some basic answers to some basic questions. Just to get used to Lua I'm just trying to make a cube spawn whereever a bullet hits a model. How would I do that? I tried some attempts last night but all I did was make the game slow down. Here is what the script looks like unmodified just as a reminder. function UpdateBullets() local bullet local pick local nextpos = Vec3(0) local emitter,model local bulletforce for bullet,nothing in pairs(bullets) do if PointDistance(bullet.origin,bullet.position)>BULLET_MAXRANGE then bullet:Free() else nextpos.x = bullet.position.x + bullet.velocity.x / 60.0 nextpos.y = bullet.position.y + bullet.velocity.y / 60.0 nextpos.z = bullet.position.z + bullet.velocity.z / 60.0 pick = LinePick( bullet.position, nextpos ) bullet.position.x = nextpos.x bullet.position.y = nextpos.y bullet.position.z = nextpos.z if pick~=nil then SetWorld(fw.transparency.world) emitter=CreateEmitter(5,700,pick.normal,1) emitter:SetVelocity( pick.normal ) emitter:SetRadius(0.1,0.5) emitter:SetWaver(10) emitter:SetColorf(0.5,0.5,0.5,0.1) emitter:Paint(material_impactdust) emitter:SetPosition( pick.position ) emitter:SetRotationSpeed(0.1) SetWorld(fw.main.world) model=GetMeshModel(pick.entity) if model~=nil then bulletforce = bullet.velocity:Normalize() d=-Dot(pick.normal,bulletforce) d=math.max(0,d) bulletforce.x = bulletforce.x * impactforce-- * d bulletforce.y = bulletforce.y * impactforce-- * d bulletforce.z = bulletforce.z * impactforce-- * d model:AddForceAtPoint( bulletforce, pick.position ) end bullet:Free() end end end end Thanks Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 21, 2010 Share Posted March 21, 2010 right after Setworld I would try something like this: cube = CreateCube() cube:SetScale(Vec3(0.2,0.2,0.2)) cube:SetPosition( pick.position ) Don't know if it works. Can't run the engine on my laptop atm. --edited my post without the error. 1 Quote Link to comment Share on other sites More sharing options...
Pancakes Posted March 21, 2010 Author Share Posted March 21, 2010 (edited) right after Setworld I would try something like this: cube = CreateCube() cube:SetScale(0.2,0.2,0.2) cube:SetPosition( pick.position ) Don't know if it works. Can't run the engine on my laptop atm. ahh, you know what that's what I tried to do but I put it on the wrong place, thanks btw SetScale gives an error "value at index 2 is not an object", I think I'm supposed to use ScaleMesh but I need to test that out some more ah, left out the Vec3 okay that was a big help thanks a lot Edited March 21, 2010 by Pancakes Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 22, 2010 Share Posted March 22, 2010 Glad it helped. So at the places where you hit a model or the scene there are now appearing boxes? Quote Link to comment Share on other sites More sharing options...
Pancakes Posted March 23, 2010 Author Share Posted March 23, 2010 Glad it helped. So at the places where you hit a model or the scene there are now appearing boxes? Yes. It's really cool. Those boxes could theoretically be chickens or decals or black holes and THINGOIDS. Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
Kazar Posted March 30, 2010 Share Posted March 30, 2010 Yes. It's really cool. Those boxes could theoretically be chickens or decals or black holes and THINGOIDS. I really like the look of that scene.. maybe its the color of the lights. Quote Core i5-750 - GTX 460 1GB - 12GB DDR3 - Win 7 x64 Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.