Jump to content

Editting Bullet.Lua


Pancakes
 Share

Recommended Posts

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

Core I5 2.67 / 16GB RAM / GTX 670

Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3

Link to comment
Share on other sites

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 by Pancakes

Core I5 2.67 / 16GB RAM / GTX 670

Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3

Link to comment
Share on other sites

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. :unsure:

post-672-12693056977157_thumb.png

Core I5 2.67 / 16GB RAM / GTX 670

Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3

Link to comment
Share on other sites

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.

Core i5-750 - GTX 460 1GB - 12GB DDR3 - Win 7 x64

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...