Jump to content

Hinge joint


AggrorJorn
 Share

Recommended Posts

I am trying to make a catapult which uses a hinge joint. Calculating the angle goes well but now I need to add a force to the catapult to shoot something. Sofar no luck with my hinge.

 

if KeyHit(KEY_SPACE)==1 then
	pos = catapult:GetPosition(1)
	catapultBody = CreateBodyPivot(pos)
	catapultBody: SetPosition( pos )
	catapultJoint = CreateJointHinge(catapultBody, catapult, pos, catapult.mat:K() )

	--Fire catapult with force
	catapult:AddTorque( Vec3( 0, 0, 10 ) )

end

 

Any suggestions?

Link to comment
Share on other sites

Hmm ... a haven't experiencies with this phys. things, but i have other idea.

Make 1st phase as animation (rotate catapult arm) and then apply force to the thing throwed from catapult. Your idea is good, but from my point of view, not all in-game solution you have to make "totaly" real :D

[HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64

[sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx

 

76561197970156808.pngAndyGFX.png

Link to comment
Share on other sites

Just using physics gives decent results... but I agree with Andy that faking the catapult throwing an object can give just as good of results and might actually give you more control over the object being shot.

 

require("scripts/constants/keycodes")
require("scripts/math/math")
RegisterAbstractPath("")
Graphics(800,600)

fw = CreateFramework()
fw.main.camera:SetPosition(Vec3(-3,6,-6))

light = CreateDirectionalLight()
light:SetRotation(Vec3(45,-45,-40) ,1)

groundphy = CreateBodyBox(100,1,100)
ground = CreateCube(groundphy)
ground:SetScale(Vec3(100,1,100))
groundphy:SetPosition(Vec3(0,-6,0))
groundphy:SetCollisionType(1)

slingphy = CreateBodyBox(12,.5,.5)
sling = CreateCube(slingphy)
sling:SetScale(Vec3(12,.5,.5))
sling:SetColor(Vec4(1,1,0,1))
slingphy:SetCollisionType(1)
slingphy:SetMass(100)

stopphy = CreateBodyBox(.2,1,1,slingphy)
stop = CreateCube(stopphy)
stop:SetScale(Vec3(.1,1,1))
stop:SetColor(Vec4(0,0,1,1))
stopphy:SetPosition(Vec3(6.2,0,0),1)
stopphy:SetCollisionType(1)

fulcrumphy = CreateBodyBox(.5,2,.5)
fulcrum = CreateCube(fulcrumphy)
fulcrum:SetScale(Vec3(.5,2,.5))
fulcrum:SetColor(Vec4(0,1,0,1))
fulcrumphy:SetPosition(Vec3(-3,-1.5,0),1)

joint = CreateJointHinge(fulcrumphy,slingphy,Vec3(-3,0,0),Vec3(0,0,1))
SetHingeJointLimits(joint,-75,45)

camerapitch=fw.main.camera.rotation.x
camerayaw=fw.main.camera.rotation.y  
SetPhysicsQuality(0)
trigger = 0 
while KeyHit(KEY_ESCAPE)==0 do
dx=Curve((MouseX()-Round(GraphicsWidth()/2))/4.0,dx,3.0/AppSpeed())        
       dy=Curve((MouseY()-Round(GraphicsHeight()/2))/4.0,dy,3.0/AppSpeed())        
       MoveMouse(Round(GraphicsWidth()/2),Round(GraphicsHeight()/2))        
       camerapitch=camerapitch+dy        
       camerayaw=camerayaw-dx        
       fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)

if KeyHit(KEY_SPACE)==1 then
	if trigger == 0 then
		trigger = 1
		slingphy:SetMassCenter(Vec3(-6,0,0))
		slingphy:AddForce(Vec3(0,.1,0))
	else
		trigger = 0
		slingphy:SetMassCenter(Vec3(6,0,0))
		slingphy:AddForce(Vec3(0,.1,0))

	end
end

if KeyHit(KEY_F)==1 then
	ammophy = CreateBodyBox(.25,.25,.25)
	ammo = CreateCube(ammophy)
	ammo:SetScale(Vec3(.25,.25,.25))
	ammo:SetColor(Vec4(1,0,1,1))
	ammophy:SetCollisionType(1)
	ammophy:SetMass(1)
               ammophy:SetFriction(1,.25)
	ammophy:SetPosition(Vec3(4.5,-4,0),1)
end

fw:Update()
fw:Render()
SetBlend(1)
DrawText("Press SPACE to Fire or Reset Catapult",0,20)
DrawText("Press F to Load Ammo in Catapult",0,40)
if ammo~= nil then
	DrawText("Ammo Position: "..ammo:GetPosition(1).x,0,60)
end
SetBlend(0)
Flip(0)
end

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

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