Jump to content

bullet help wanted


diedir
 Share

Recommended Posts

Hi all

i need some help please,

i already can make appear a cube in front of my running car

but i can't figure how to throw it toward the z axis of the car and addforce (punching) the model (another car) in front of it

 

here is my current code (not working at the addforceatpoint line)

 

	                             ----retourne camera position
				local i=TFormVector(Vec3(0,0,9),camera,nil)
				i=Vec3(camera:GetPosition(1).x +i.x,camera:GetPosition(1).y -2.5,camera:GetPosition(1).z +i.z)
				---position projectile
				projectile:SetPosition(i)
				--position phyproj
				phyproj:SetPosition(i)
                                       --------------------------------
				--this next line not working
				phyproj:AddForceAtPoint(Vec3(0,0,-2),Vec3(projectile.position.x,projectile.position.y,projectile.position.z+0.5))

 

my code is based on 3rd view chasing camera

 

thanks a lot for viewing and much more for helping :)

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

Is the box (projectile) just a create cube you are making and the phyproj is its body? if you parent those you shouldn't have to set the position for both... Also, try AddForce instead of AddForceAtPoint.

Try this and see if it helps:

require("Scripts/constants/keycodes")
require("Scripts/math/math")
RegisterAbstractPath("")        
Graphics(800,600)        
fw=CreateFramework()        

light = CreateDirectionalLight()
light:SetRotation(Vec3(45,45,45))

camerapitch=fw.main.camera.rotation.x
camerayaw=fw.main.camera.rotation.y

HideMouse()
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
DebugPhysics(1)
while KeyHit(KEY_ESCAPE)==0 do        
gx=Round(GraphicsWidth()/2)        
gy=Round(GraphicsHeight()/2)        
dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())        
dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())        
MoveMouse(gx,gy)        
camerapitch=camerapitch+dy        
camerayaw=camerayaw-dx        
camerapitch=math.min(camerapitch,90)        
camerapitch=math.max(camerapitch,-89.99)       
fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)        

if MouseHit(1)==1 then
	phyproj = CreateBodyBox(1,1,1)
	projectile = CreateCube(phyproj)
	projectile:SetColor(Vec4(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255,1))
	phyproj:SetMass(1)
	local V = TFormVector(Vec3(0, 0, 2), fw.main.camera, nil)
	V = Vec3(fw.main.camera.position.x + V.x, fw.main.camera.position.y + V.y, fw.main.camera.position.z + V.z)
	PositionEntity(phyproj, V, 0)
	RotateEntity(phyproj, EntityRotation(fw.main.camera, 0), 0)
	phyproj:AddForcef(0, 100, 1500, 0)
end

fw:Update() 
fw:Render()
       DrawText("Press left mouse button to fire a cube",0,40)
Flip(0)
end
ShowMouse()

  • Upvote 2

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

thanks i will try sooner

and yes they are parented, thanks for the tip

-----------------------------------------------------------------

EDIT:

Really want to thank you Mack !

it works great my lord !

 

I owe you two or three beers or

easier for me a fresh bottle of white wine like "Sancerre" or "Mâcon Uchisy" (if you come to France, tell me where and when)

you already saved my poor knowledge code :)

-----------------------------------------------------------------

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

 

I owe you two or three beers or

easier for me a fresh bottle of white wine like "Sancerre" or "Mâcon Uchisy" (if you come to France, tell me where and when)

you already saved my poor knowledge code :)

-----------------------------------------------------------------

I really should get my business going up and running: http://leadwerks.com/werkspace/index.php?/topic/2434-beer-online/

So many people on Leadwerks want to treat others who helped them on a beer.

 

But that is a nice script macklebee. Shooting boxes is always a lot of fun.

Link to comment
Share on other sites

Yes Aggror, could be a must and very busy business :)

 

Guys i need one (lier) more thing for my level:

 

-i have a car loaded in 3rd view camera

-i want to retrieve the speed (velocity) of my car

 

i can't have this to work:

 

myspeed=chassis:GetVelocity(1).z

 

leads to an index error...

all my attempts to get the tirespeed or carobject.vehicle speed failed.

i'm lost here

 

thanks for help

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

I don't think velocity will also take forces into account, but if you get hit from behind by another car (or explosion or whatever) you are traveling faster, from the front you'll travel slower.

So... why not just calculate the distance traveled every 10 frames or so (I guess some formula using currentposition, previousposition and appspeed)

desktop: Quad core Q6600 + 4GB + ATI HD4890 + XP

laptop: Dual core T6400 + 4 GB + NVidia 9600M GT + Vista 32

Link to comment
Share on other sites

Something like this?

 

Outside you main loop:

CarPreviousPosition = CreatePivot()
TotalCounter = 0

 

Inside your main loop:

TotalCounter = TotalCounter + 1
if (TotalCounter % 60 == 0) then
-- Calculate distance traveled last 60 frames
local dist = EntityDistance(car,CarPreviousPosition)
Print("traveling at " .. (dist * 3.6) .. " km/hour")
CarPreviousPosition:SetPosition(car.position)
end

desktop: Quad core Q6600 + 4GB + ATI HD4890 + XP

laptop: Dual core T6400 + 4 GB + NVidia 9600M GT + Vista 32

Link to comment
Share on other sites

thanks for the code look really easier than i thought, i will try this at home

(shhht) i am at wrk now...

 

Thanks a lot

great community here i am happy ! :))

 

EDIT:

 

Your code works as i wanted, very helpful for me. :)

 

 

Thanks a lot

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

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