Jump to content

Gilmer

Members
  • Posts

    293
  • Joined

  • Last visited

Posts posted by Gilmer

  1. Yes, the wheels continues with the speed it was before I place in new position. But I used that Lumooja said, it's working. The only problem is that if the car is running in a curve, and while accelerate, if is positioned for a new position, the car go, stay stopped, but is turning to side that was turning before go to new position.

     

    I can't explain better, but if u run this script, go to front, and right, in same time, it's will turn to right, when get a great velocity, press SPACE, and you will see whats happened. :D

  2. An example, of what I want. This is the script of driver.lua, of viperscout. I just add this IF in main loop:

     

    require("Scripts/constants/keycodes")
    require("Scripts/linkedlist")
    require("Scripts/filesystem")
    require("scripts/math/math")
    require("scripts/constants/engine_const")
    
    FlushKeys()
    HideMouse()
    
    local camera = fw.main.camera
    
    chassis=LoadModel("abstract::vehicle_viperscout.gmf")
    carobject=objecttable[chassis]
    car=carobject.vehicle
    
    if car==nil then
    Notify("Vehicle object not found.",1)
    chassis:Free()
    return
    end
    
    chassis:SetPosition(TFormPoint(Vec3(0,-1,10),fw.main.camera,nil))
    chassis:SetRotationf(0,camera.rotation.y+180.0,0)
    
    --Variables
    local dx=0.0
    local dy=0.0
    local camerapitch=camera.rotation.x
    local camerayaw=camera.rotation.y
    local move=0.0
    local strafe=0.0
    local steering = 0.0
    local torque = 0.0
    local steerlimit = 30.0
    local steerrate = 2.0
    local steerangle=0.0
    
    MoveMouse(Round(GraphicsWidth()/2),Round(GraphicsHeight()/2))
    
    while KeyHit(KEY_ESCAPE)==0 do	
    
    --Camera look
    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,-90)
    fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)
    
    local tirespeed=-(KeyDown(KEY_UP)-KeyDown(KEY_DOWN))*2.0
    car:AddTireTorque(tirespeed,0)
    car:AddTireTorque(tirespeed,1)
    car:AddTireTorque(tirespeed,2)
    car:AddTireTorque(tirespeed,3)
    
    steermode=0
    if KeyDown(KEY_RIGHT)==1 then steermode=steermode-1 end
    if KeyDown(KEY_LEFT)==1 then steermode=steermode+1 end
    
    if steermode==1 then
    	steerangle=steerangle+4.0*AppSpeed()
    elseif steermode==-1 then
    	steerangle=steerangle-4.0*AppSpeed()
    else
    	if steerangle>0 then
    		steerangle=steerangle-4.0*AppSpeed()
    		if steerangle<0.0 then steerangle=0.0 end
    	else
    		steerangle=steerangle+4.0*AppSpeed()
    		if steerangle>0.0 then steerangle=0.0 end
    	end
    end
    steerangle=Clamp(steerangle,-25,25)
    
    car:SetSteerAngle(steerangle,0)
    car:SetSteerAngle(steerangle,1)
    
    fw:Update()
    
    local campos=TFormPoint(Vec3(0,1,0),chassis,nil)
    
    fw.main.camera:SetPosition(campos)
    fw.main.camera:Move(Vec3(0,0,-10))
    
    local t=TFormVector(Vec3(0,0,1),camera,chassis)
    a=-math.deg(math.atan2(t.x,t.z))+180.0
    
    carobject.turret:SetRotationf(0,CurveAngle(a,carobject.turret.rotation.y,10.0/AppSpeed()),0)
    
    chassis:Hide()
    local pick = LinePick(campos,camera.position,0.5,COLLISION_PROP)
    chassis:Show()
    if pick~=nil then
    	camera:SetPosition(pick.position)
    end
    
    if(KeyHit(KEY_SPACE)==1) then
    	chassis:SetPosition(Vec3(0,0,0))
    end
    
    fw:Render()
    Flip(0)
    end
    
    chassis:Free()
    chassis=nil
    camera=nil
    
    ShowMouse()
    

     

    if(KeyHit(KEY_SPACE)==1) then
        chassis:SetPosition(Vec3(0,0,0))
    end
    

     

    If you are running with the car normally, and press SPACE, the car is back to position (0,0,0), but continue with velocity. I want to the car back to pos(0,0,0), and stay stopped, ie, without force..

  3. A while ago I made this script, for now I using this.. :)

     

    require("scripts/class")
    local class=CreateClass(...)
    
    function class:InitDialog(grid)
    self.super:InitDialog(grid)
    group=grid:AddGroup("Scale")
    group:AddProperty("Scale",PROPERTY_FLOAT,"1,4,2")
    group:Expand(1)
    end
    
    function class:CreateObject(model)
    local object=self.super:CreateObject(model)
    
    object.model:SetKey("scale","1")
    
    
    function object:SetKey(key,value)
    	if key=="scale" then
    		self.scale=tonumber(value)
    		model:SetScalef(self.scale,self.scale,self.scale,0)
    	else
    		return self.super:SetKey(key,value)
    	end
    	return 1
    end
    
    end
    

  4. Yes, eg: the car is moving normally, and in certain moment, it's moved to position (0,0,0). But I want it is positioned, and stay stopped in new positioned. Whats occurring, is that it's being positioned and continues going to front, because of force applied in the wheels..

     

    I'm using C/C++

  5. I'm with a doubt. When my car vehicle get out the road, it pass over a trigger, that return back the car to road in certain position. The problem, is that when it pass in some trigger, it have a velocity, and when back to center road, the velocity coninue, but I need that the car back to the road stopped, like in all game cars, when the player get out from road.

     

    I used:

    SetBodyVelocity(car,Vec3(0,0,0),0);
    SetBodyOmega(car,Vec3(0,0,0),0);

     

    The car back to road stopped, but after millisecs for sample, it begins to turn to right or left randomly, like if have some forces applying over car.

     

    What function I can use to "reset" the force in vehicle, and torques in tires?!

     

    thx

  6. Sad...

    I did some searches too, and see that in the own Newton's forum is talked about it. Well, I'll try simulate this with animations "pre-made", or use other model in the place. However, thanks Josh for feedback..

  7. Hello guys...

     

    As I posted in other topic, I'm trying create a cloth system, to apply in a model. I created a rope with node and joints between it. The nodes I parented in bones, and "apply" physics them. My first problem I was solved, that the performance problem, so I did that talked in other topic, in slice in areas, and go activating the mass...

     

    Well, the problem now, is when the model falls, the nodes are "fighting", and not stop, as if are trying enter into the other..

     

    Have some function to solve this...or some way???

     

    A video, of whats happening:

     

  8. Hi peoples. I'm having a big problem with the performace, and dont know to solve.

     

    I created a model of a grid. I wanna it have reaction with the physics if the car collide with it, or bursts. So far so good, I used there rope system, and convert to Lua in the model.

     

    The Problem, this is a scene to race game, have a lot models like it in the road. So when begin the scene, the FPS start extremely low.

     

    Cause at the start, the physics begins working in ever models.

     

    Have someway to begins with some model physics, stoped? And begins to work, just when the camera is near?

     

    Or some other way, to could optmize the performance of model physics reaction?

     

    Below, is the code that I'm using. Just to be clear, inside model, have some bones: "bones1","bones2"....until the 14, that is parented to physics nodes.

     

    require("scripts/class")
    require("Scripts/constants/collision_const")
    local class=CreateClass(...)
    
    function class:InitDialog(grid)
    self.super:InitDialog(grid)
    group=grid:AddGroup("Configuration")
    group:AddProperty("Thikness",PROPERTY_FLOAT,"0,1,2")
    group:AddProperty("Nodes",PROPERTY_FLOAT,"1,7,0.05")
    group:AddProperty("Attached",PROPERTY_CHOICE,"0,1","Attached")
    group:Expand(1)
    end
    
    
    function class:CreateObject(model)
    local object=self.super:CreateObject(model)
    
    
    -- Ini sets
    local Nodesq
    local Thikness
    local Attached
    
    
    -- Local variables
    local FPLoop
    local nxrnd
    local Could
    local startBody
    local endBody
    local lenght
    local BodyNodes={2}
    BodyNodes[0]={Nodesq}
    BodyNodes[1]={Nodesq}
    BodyNodes[2]={Nodesq}
    
    local firstJoint={}
    local lastJoint={}
    local nodePos={}
    local nodeJoint={}
    
    local pivot1
    local pivot2
    local pivot3
    local pivot4
    local pivot5
    local pivot6
    local pivot7
    local pivot8
    local pivot9
    
    local bones1
    local bones2
    local bones3
    local bones4
    local bones5
    local bones6
    local bones7
    local bones8
    local bones9
    local bones10
    local bones11
    local bones12
    local bones13
    local bones14
    
    -- Estacas
    local estaca1
    local estaca1pos
    local estaca2
    local estaca2pos
    local estacaJoint={}
    local estaca1Mesh
    local estaca2Mesh
    local startPoint={}
    local endPoint={}
    local Pivo1Joint={}
    local Pivo2Joint={}
    local lastBodyNodes={}
    local PivotStart = {}
    local PivotEnd = {}
    local SelfPivot
    local SelfPivot2
    
    function object:UpdateModel()
    	-- Ini sets
    	object.model:SetKey("Thikness","0.05")
    	object.model:SetKey("Nodes","7")
    	object.model:SetKey("Attached","1")
    	Nodesq = tonumber(object.model:GetKey("Nodes"))
    
    	--self:Clear()
    
    	Nodesq = tonumber(object.model:GetKey("Nodes"))
    	Thikness = tonumber(object.model:GetKey("Thikness"))
    	Attached = tonumber(object.model:GetKey("Attached"))
    
    
    	-- Local variables
    	FPLoop = 0
    	nxrnd = 3-- math.random(5)
    	Could = 0
    	startBody = {}
    	endBody = {}
    	BodyNodes={2}
    	BodyNodes[0]={Nodesq}
    	BodyNodes[1]={Nodesq}
    	BodyNodes[2]={Nodesq}
    
    	firstJoint={}
    	lastJoint={}
    	nodePos={}
    	nodeJoint={}
    
    	pivot1 = FindChild(object.model,"pivot01")
    	pivot2 = FindChild(object.model,"pivot02")
    	pivot3 = FindChild(object.model,"pivot03")
    	pivot4 = FindChild(object.model,"pivot04")
    	pivot5 = FindChild(object.model,"pivot05")
    	pivot6 = FindChild(object.model,"pivot06")
    	pivot7 = FindChild(object.model,"pivot07")
    	pivot8 = FindChild(object.model,"pivot08")
    	pivot9 = FindChild(object.model,"pivot09")
    
    
    	bones1 = FindChild(object.model,"Bone01")
    	bones2 = FindChild(object.model,"Bone02")
    	bones3 = FindChild(object.model,"Bone03")
    	bones4 = FindChild(object.model,"Bone04")
    	bones5 = FindChild(object.model,"Bone05")
    	bones6 = FindChild(object.model,"Bone06")
    	bones7 = FindChild(object.model,"Bone07")
    	bones8 = FindChild(object.model,"Bone08")
    	bones9 = FindChild(object.model,"Bone09")
    	bones10 = FindChild(object.model,"Bone10")
    	bones11 = FindChild(object.model,"Bone11")
    	bones12 = FindChild(object.model,"Bone12")
    	bones13 = FindChild(object.model,"Bone13")
    	bones14 = FindChild(object.model,"Bone14")
    
    	estacaJoint={}
    
    
    	estaca1 = CreateBodyCylinder(0.1,(pivot3:GetPosition(1).y)-(pivot1:GetPosition(1).y))
    	estaca1:SetPosition(pivot1:GetPosition(1))
    	estaca1pos = (pivot1:GetPosition(1).y)-(pivot3:GetPosition(1).y)
    	estaca1:Move(Vec3(0,(-estaca1pos*.5),0))
    	estaca1:SetMass(0.01)
    
    	estaca2 = CreateBodyCylinder(0.1,(pivot4:GetPosition(1).y)-(pivot2:GetPosition(1).y))
    	estaca2:SetPosition(pivot2:GetPosition(1))
    	estaca2pos = (pivot2:GetPosition(1).y)-(pivot4:GetPosition(1).y)
    	estaca2:Move(Vec3(0,(-estaca2pos*.5),0))
    	estaca2:SetMass(0.01)
    
    	estaca1:SetDamping(0,0)
    	estaca2:SetDamping(0,0)
    
    	estaca1Mesh = LoadModel("abstract::Tales_Rede_taco.gmf")
    	estaca2Mesh = LoadModel("abstract::Tales_Rede_taco.gmf")
    
    	EntityParent(estaca1Mesh,estaca1)
    	EntityParent(estaca2Mesh,estaca2)
    
    	estaca1Mesh:SetPosition(estaca1:GetPosition(),1)
    	estaca2Mesh:SetPosition(estaca2:GetPosition(),1)
    
    
    	startPoint={}
    	startPoint[0] = pivot1:GetPosition(1)
    	startPoint[1] = pivot3:GetPosition(1)
    	startPoint[2] = pivot5:GetPosition(1)
    	endPoint={}
    	endPoint[0] = pivot2:GetPosition(1)
    	endPoint[1] = pivot4:GetPosition(1)
    	endPoint[2] = pivot6:GetPosition(1)
    
    	Pivo1Joint={}
    	Pivo2Joint={}
    
    	lastBodyNodes={}
    
    
    	-- Temp, Mudar depois para os pivos do modelo
    
    
    	PivotStart = {}
    	PivotEnd = {}
    	PivotStart[0] = CreateBodyBox(0.1,0.1,0.1)
    	PivotEnd[0]  = CreateBodyBox(0.1,0.1,0.1)
    
    	PivotStart[1] = CreateBodyBox(0.1,0.1,0.1)
    	PivotEnd[1]  = CreateBodyBox(0.1,0.1,0.1)
    
    	PivotStart[2] = CreateBodyBox(0.1,0.1,0.1)
    	PivotEnd[2]  = CreateBodyBox(0.1,0.1,0.1)
    
    
    	PivotStart[0]:SetPosition(startPoint[0])
    	PivotEnd[0]:SetPosition(endPoint[0])
    	PivotStart[1]:SetPosition(startPoint[1])
    	PivotEnd[1]:SetPosition(endPoint[1])
    	PivotStart[2]:SetPosition(startPoint[2])
    	PivotEnd[2]:SetPosition(endPoint[2])
    
    
    	for ii=0,2 do
    
    		startBody[ii] = CreateBodyBox(0.1,0.1,0.1)
    		endBody[ii]   = CreateBodyBox(0.1,0.1,0.1)
    		startBody[ii]:SetPosition(startPoint[ii])
    		endBody[ii]:SetPosition(endPoint[ii])
    
    		startBody[ii]:SetMass(0.05)
    		endBody[ii]:SetMass(0.05)
    
    		lenght = (EntityDistance(startBody[ii],endBody[ii])/Nodesq)
    
    		BodyNodes[ii][0] = CreateBodyBox(Thikness,lenght,Thikness)
    		BodyNodes[ii][0]:SetMass(0.05)
    		BodyNodes[ii][0]:SetPosition(startPoint[ii],1)
    		BodyNodes[ii][0]:Point(endBody[ii],1)
    		BodyNodes[ii][0]:Point(endBody[ii],2)
    		BodyNodes[ii][0]:Point(endBody[ii],3)
    		BodyNodes[ii][0]:Turn(Vec3(90,283,90))
    		BodyNodes[ii][0]:Move(Vec3(0,lenght/2,0))
    		BodyNodes[ii][0]:SetCollisionType(1,1)
    
    		Collisions(1,1,1)
    
    		Pivo1Joint[ii] = CreateJointBall(startBody[ii],PivotStart[ii],startPoint[ii],Vec3(0,0,0))
    		Pivo2Joint[ii] = CreateJointBall(endBody[ii],PivotEnd[ii],endPoint[ii],Vec3(s0,0,0))
    
    
    		for i=1,(Nodesq-1) do
    			BodyNodes[ii][i] = CopyEntity(BodyNodes[ii][0])
    
    			lastBodyNodes[ii] = BodyNodes[ii][i-1]:GetPosition()
    
    			BodyNodes[ii][i]:SetPosition(lastBodyNodes[ii],1)
    			BodyNodes[ii][i]:Point(endBody[ii],1)
    			BodyNodes[ii][i]:Point(endBody[ii],2)
    			BodyNodes[ii][i]:Point(endBody[ii],3)
    			BodyNodes[ii][i]:Turn(Vec3(0,0,0))
    			BodyNodes[ii][i]:Move(Vec3(0,lenght,0))
    			BodyNodes[ii][i]:SetCollisionType(1,1)
    			BodyNodes[ii][i]:SetDamping(0,0)
    
    			nodePos[ii] = BodyNodes[ii][i]:GetPosition()
    
    			nodeJoint[ii] = CreateJointBall(BodyNodes[ii][i-1],BodyNodes[ii][i],Vec3(nodePos[ii].x,nodePos[ii].y,nodePos[ii].z+(lenght/2)),Vec3(0,0,0))
    			nodeJoint[ii]:SetLimits(Vec3(0,1,0),90)
    
    		end
    
    	end
    
    	-- Joint das estacas
    	EntityParent(bones1,BodyNodes[0][0],1)
    	EntityParent(bones7,BodyNodes[0][6],1)
    	EntityParent(bones8,BodyNodes[1][0],1)
    	EntityParent(bones14,BodyNodes[1][6],1)
    
    
    
    	firstJoint[0] = CreateJointBall(startBody[0], estaca1, startPoint[0],Vec3(0,0,0))
    	firstJoint[1] = CreateJointBall(startBody[1], estaca1, startPoint[1],Vec3(0,0,0))
    	firstJoint[2] = CreateJointBall(startBody[2], estaca1, startPoint[2],Vec3(0,0,0))
    
    	if Attached==1 then
    		lastJoint[0] = CreateJointBall(endBody[0],estaca2, endPoint[0],Vec3(0,0,0))
    		lastJoint[1] = CreateJointBall(endBody[1],estaca2, endPoint[1],Vec3(0,0,0))
    		lastJoint[2] = CreateJointBall(endBody[2],estaca2, endPoint[2],Vec3(0,0,0))
    	end
    
    
    	estacaJoint[0] = CreateJointBall(estaca1,BodyNodes[0][0], startPoint[0])
    	estacaJoint[0]:SetLimits(Vec3(0,1,0),90)
    	estacaJoint[1] = CreateJointBall(estaca1,BodyNodes[1][0], startPoint[1])
    	estacaJoint[1]:SetLimits(Vec3(0,1,0),90)
    
    	estacaJoint[2] = CreateJointBall(estaca2,BodyNodes[0][Nodesq-1], endPoint[0])
    	estacaJoint[2]:SetLimits(Vec3(0,1,0),90)
    	estacaJoint[3] = CreateJointBall(estaca2,BodyNodes[1][Nodesq-1], endPoint[1])
    	estacaJoint[3]:SetLimits(Vec3(0,1,0),90)
    
    	estacaJoint[4] = CreateJointBall(estaca1,BodyNodes[2][0], startPoint[2])
    	estacaJoint[4]:SetLimits(Vec3(0,1,0),90)
    	estacaJoint[5] = CreateJointBall(estaca2,BodyNodes[2][Nodesq-1], endPoint[2])
    	estacaJoint[5]:SetLimits(Vec3(0,1,0),90)
    
    
    end
    
    
    function object:Free()
    	self:Clear()
    	self.super:Free()
    end
    
    
    function object:Update()
    
    	bones2:SetPosition(BodyNodes[0][1]:GetPosition(1),1)
    	bones3:SetPosition(BodyNodes[0][2]:GetPosition(1),1)
    	bones4:SetPosition(BodyNodes[0][3]:GetPosition(1),1)		
    	bones5:SetPosition(BodyNodes[0][4]:GetPosition(1),1)
    	bones6:SetPosition(BodyNodes[0][5]:GetPosition(1),1)
    	bones9:SetPosition(BodyNodes[1][1]:GetPosition(1),1)
    	bones10:SetPosition(BodyNodes[1][2]:GetPosition(1),1)
    	bones11:SetPosition(BodyNodes[1][3]:GetPosition(1),1)
    	bones12:SetPosition(BodyNodes[1][4]:GetPosition(1),1)
    	bones13:SetPosition(BodyNodes[1][5]:GetPosition(1),1)
    
    
    
    	-- Distancia Nodes Centrais X
    	local nx = EntityDistance(BodyNodes[2][3],BodyNodes[2][0])
    
    	-- Distancia Nodes Centrais Y1
    	local ny1 = 0
    	local ny1b = 0
    
    	if(Nodesq==nil) then
    		Nodesq = tonumber(object.model:GetKey("Nodes"))
    	end
    
    	for i=0, (Nodesq-1) do
    		ny1 = EntityDistance(BodyNodes[1][i],BodyNodes[0][i])
    		if(ny1>2) then ny1b = 1 end
    	end
    
    	-- Distancia Nodes Centrais Y2
    	local ny2 = 0
    	local ny2b = 0
    	for i=0, (Nodesq-1) do
    		ny2 = EntityDistance(BodyNodes[2][i],BodyNodes[1][i])
    		if(ny2>2) then ny2b = 1 end
    	end
    
    
    
    	if(nx>=3 or ny1b==1 or ny2b==1) then
    
    		if(nxrnd==1) then
    			FreeJoint(firstJoint[0])
    			FreeJoint(firstJoint[1])
    			FreeJoint(firstJoint[2])
    		end
    
    		if(nxrnd==2) then
    			if Attached==1 then
    				FreeJoint(lastJoint[0])
    				FreeJoint(lastJoint[1])
    				FreeJoint(lastJoint[2])
    			end
    		end
    
    		if(nxrnd~=1 and nxrnd~=2) then
    			FreeJoint(firstJoint[0])
    			FreeJoint(firstJoint[1])
    			FreeJoint(firstJoint[2])
    			if Attached==1 then
    				FreeJoint(lastJoint[0])
    				FreeJoint(lastJoint[1])
    				FreeJoint(lastJoint[2])
    			end
    
    		end
    
    		object.model:SetPosition(BodyNodes[1][3]:GetPosition(1))
    
    
    		FPLoop = FPLoop + 1
    
    		if(FPLoop>300 and Could==0) then
    
    			Could = 1
    
    			for i=0,(Nodesq-1) do
    				BodyNodes[0][i]:Free()
    				BodyNodes[1][i]:Free()
    				BodyNodes[2][i]:Free()
    			end
    
    			estaca1:SetCollisionType(0,0)
    			estaca1:SetMass(0)
    			estaca2:SetCollisionType(0,0)
    			estaca2:SetMass(0)
    
    			startBody[0]:SetCollisionType(0,0)
    			startBody[0]:SetMass(0)
    			startBody[1]:SetCollisionType(0,0)
    			startBody[1]:SetMass(0)
    			startBody[2]:SetCollisionType(0,0)
    			startBody[2]:SetMass(0)
    			endBody[0]:SetCollisionType(0,0)
    			endBody[0]:SetMass(0)
    			endBody[1]:SetCollisionType(0,0)
    			endBody[1]:SetMass(0)
    			endBody[2]:SetCollisionType(0,0)
    			endBody[2]:SetMass(0)
    
    			PivotStart[0]:SetCollisionType(0,0)
    			PivotStart[0]:SetMass(0)
    			PivotStart[1]:SetCollisionType(0,0)
    			PivotStart[1]:SetMass(0)
    			PivotStart[2]:SetCollisionType(0,0)
    			PivotStart[2]:SetMass(0)
    			PivotEnd[0]:SetCollisionType(0,0)
    			PivotEnd[0]:SetMass(0)
    			PivotEnd[1]:SetCollisionType(0,0)
    			PivotEnd[1]:SetMass(0)
    			PivotEnd[2]:SetCollisionType(0,0)
    			PivotEnd[2]:SetMass(0)
    
    			startBody[0]:Free()
    			startBody[1]:Free()
    			startBody[2]:Free()
    			endBody[0]:Free()
    			endBody[1]:Free()
    			endBody[2]:Free()
    			PivotStart[0]:Free()
    			PivotStart[1]:Free()
    			PivotStart[2]:Free()
    			PivotEnd[0]:Free()
    			PivotEnd[1]:Free()
    			PivotEnd[2]:Free()
    
    			pivot1:Free()
    			pivot2:Free()
    			pivot3:Free()
    			pivot4:Free()
    			pivot5:Free()
    			pivot6:Free()
    
    		end
    
    	end
    
    end
    
    function object:Clear()
    
    	Thikness	= nil
    	Attached	= nil
    	lenght 		= nil
    	pivot1 		= nil
    	pivot2 		= nil
    	pivot3 		= nil
    	pivot4 		= nil
    	pivot5 		= nil
    	pivot6 		= nil
    	bones1 	= nil
    	bones2 	= nil
    	bones3 	= nil
    	bones4 	= nil
    	bones5 	= nil
    	bones6 	= nil
    	bones7 	= nil
    	bones8 	= nil
    	bones9 	= nil
    	bones10 	= nil
    	bones11 	= nil
    	bones12 	= nil
    	bones13 	= nil
    	bones14 	= nil
    	if(estaca1~=nil) then estaca1:Free() end
    	estaca1pos 	= nil
    	if(estaca2~=nil) then estaca2:Free() end
    	estaca2pos 	= nil
    	estaca1Mesh 	= nil
    	estaca2Mesh 	= nil
    	startPoint[0] 	= nil
    	startPoint[1] 	= nil
    	startPoint[2] 	= nil
    	endPoint[0] 	= nil
    	endPoint[1] 	= nil
    	endPoint[2] 	= nil
    	if(PivotStart[0]~=nil) then PivotStart[0]:Free() end
    	if(PivotStart[1]~=nil) then PivotStart[1]:Free() end
    	if(PivotStart[2]~=nil) then PivotStart[2]:Free() end
    	if(PivotEnd[0]~=nil) then PivotEnd[0]:Free() end
    	if(PivotEnd[1]~=nil) then PivotEnd[1]:Free() end
    	if(PivotEnd[2]~=nil) then PivotEnd[2]:Free() end
    
    	for i=0,(Nodesq-1) do
    		if(BodyNodes[0][i]~=nil) then BodyNodes[0][i]:Free() end
    		if(BodyNodes[1][i]~=nil) then BodyNodes[1][i]:Free() end
    		if(BodyNodes[2][i]~=nil) then BodyNodes[2][i]:Free() end
    	end
    
    	Nodesq 		= nil
    end
    
    
    
    object:UpdateModel()
    
    
    
    end
    

     

     

    And a video in action:

  9. Hi, i'm trying do a rope system, and I found this topic: http://leadwerks.com...h__1#entry23004

    And I used the example of MasteR. Had some bugs, and I fix it. But the problem that I'm having, I can't move the first node, like move a Entity. It move, but have a little "delay" in your movement. I dont know if is cause he's as TBody.

     

    I tried use CalcBodyVelocity() and AddBodyForce() too, but I dont had luck. My code is this, i need so much this. Just for clarity, I wanna use this as a cloth fence, where the extremities will fixed, and in the center will fall. Then the nodes of rope, will be the "bones" to model. But this model will move, then the rope with nodes need move together, in the same position.

     

    Here is my code, if need, I try explain in other way...thanks

     

     

    [Cable.h]

     

    #include "leo.h"
    
    class CPhysicsCable
    {
    private:
    	int pNodes;
    	TVec3 pStartPoint;
    	TVec3 pEndPoint;
    	float pThickness;
    	bool pAttached;
    	float pLength;	
    	TVec3 nodePos;
    	TVec3 Calc;
    
    public:
    	TEntity *pBodyNodes;
    	TEntity *pMeshNodes;
    	TVec3 TempPos;
    	TEntity start;
    	TEntity end;
    	TEntity firstJoint;
    	TEntity pPivotStart;
    	TEntity pPivotEnd;
    
    	CPhysicsCable(TVec3 aStart, TVec3 aEnd, float aThickness, int aNodes, bool aAttached,TEntity aPivotStart,TEntity aPivotEnd)
    	{
    		pNodes = aNodes;
    		pStartPoint = aStart;
    		pEndPoint = aEnd;
    		pThickness = aThickness;
    		pAttached = aAttached;
    		pLength = 0.0;
    		pMeshNodes = new TEntity[pNodes];
    		pBodyNodes = new TEntity[pNodes];
    		pPivotStart = aPivotStart;
    		pPivotEnd = aPivotEnd;
    		Create();
    	}
    
    	void Create()
    	{
    		start = CreateBodyBox(0.1, 0.1, 0.1, 0);
    		end = CreateBodyBox(0.1, 0.1, 0.1, 0);
    		PositionEntity(start, pStartPoint);
    		PositionEntity(end, pEndPoint);
    
    		pLength = EntityDistance(start, end)/pNodes;
    
    		pMeshNodes[0] = CreateCylinder(6, 1, 0);
    		TMaterial material = LoadMaterial("abstract::Cable_node.mat");
    		PaintEntity(pMeshNodes[0],material);
    		ScaleEntity(pMeshNodes[0], Vec3(pThickness, pLength, pThickness));
    		pBodyNodes[0] = CreateBodyBox(pThickness, pLength, pThickness);
    		SetBodyMass(pBodyNodes[0], 0.1);
    		EntityType(pBodyNodes[0], 1);
    		EntityParent(pMeshNodes[0], pBodyNodes[0]);
    		PositionEntity(pBodyNodes[0], pStartPoint, 1);
    		PointEntity(pBodyNodes[0], end, 1);
    		PointEntity(pBodyNodes[0], end, 2);
    		PointEntity(pBodyNodes[0], end, 3);
    		TurnEntity(pBodyNodes[0], Vec3(90.0, 0.0, 0.0), 0);
    		MoveEntity(pBodyNodes[0], Vec3(0.0, pLength/2.0, 0.0), 0);
    
    		firstJoint = CreateJointBall(start, pBodyNodes[0], pStartPoint, Vec3(0.0, 0.0, 0.0));
    		SetBallJointLimits(firstJoint, 180.0, 180.0, 180.0);
    
    		for(int i=1; i<pNodes; i++)
    		{
    			pMeshNodes[i] = CopyEntity(pMeshNodes[0]);
    			pBodyNodes[i] = CopyEntity(pBodyNodes[0]);
    			EntityParent(pMeshNodes[i], pBodyNodes[i]);
    			PositionEntity(pBodyNodes[i], EntityPosition(pBodyNodes[i-1]), 1);
    			PointEntity(pBodyNodes[i], end, 1);
    			PointEntity(pBodyNodes[i], end, 2);
    			PointEntity(pBodyNodes[i], end, 3);
    			TurnEntity(pBodyNodes[i], Vec3(90.0, 0.0, 0.0), 0);
    			MoveEntity(pBodyNodes[i], Vec3(0.0, pLength, 0.0), 0);
    
    			nodePos = EntityPosition(pBodyNodes[i]);
    			TEntity nodeJoint = CreateJointBall(pBodyNodes[i-1], pBodyNodes[i], Vec3(nodePos.X, nodePos.Y, nodePos.Z+(pLength/2.0)), Vec3(0.0, 0.0, 0.0));
    			SetBallJointLimits(nodeJoint, 0.0, 180.0, 180.0);
    		 }
    
    		if(pAttached==1)
    		{
    			TEntity lastJoint = CreateJointBall(pBodyNodes[pNodes-1], end, pEndPoint, Vec3(0.0, 0.0, 0.0));
    			SetBallJointLimits (lastJoint, 180.0, 180.0, 180.0);
    		}
    	}
    
    	void Update()
    	{
    
    		PositionEntity(start,EntityPosition(pPivotStart));
    
    };
    
    

     

    [main]

     

    #include "engine.h"
    #include "Cable.h"
    
    int WINAPI WinMain( HINSTANCE hInstance,
    				HINSTANCE hPrevInstance,
    				LPSTR lpCmdLine,
    				int nShowCmd ) 
    {
    Initialize() ;
    RegisterAbstractPath("D:/Projetos/Rally");
    SetAppTitle( "Cables" ) ;
    Graphics( 800, 600 ) ;
    AFilter() ;
    TFilter() ;
    
    TLight	light;
    TMesh	ground;
    TMaterial material;
    
    TFramework framework=CreateFramework();
       TLayer layer = GetFrameworkLayer(0);
    TCamera camera=GetLayerCamera(layer);
    
    light=CreateDirectionalLight();
    RotateEntity(light,Vec3(45,45,45));
    PositionEntity(camera,Vec3(0,0,-2));
    
    float sx = -2;
    float sy = 1;
    float sz = 2;
    
    float ex = 2;
    float ey = 1;
    float ez = 2;
    
    TEntity c=CreateCube();
    PositionEntity(c,Vec3(sx,sy,sz));
    ScaleEntity(c,Vec3(0.2,0.2,0.2));
    
    TEntity c2=CreateCube();
    PositionEntity(c2,Vec3(ex,ey,ez));
    ScaleEntity(c2,Vec3(0.2,0.2,0.2));
    
    
    TVec3 startPos = Vec3(sx,sy,sz);
    TVec3 endPos = Vec3(2,1,2);
    CPhysicsCable* Cable = new CPhysicsCable(startPos,endPos,0.1,50,1,c,c2);
    
    TEntity sphere = CreateSphere();
    ScaleEntity(sphere,Vec3(0.3,0.3,0.3));
    
    TVec3 CalcPos;
    SetBodyVelocity(Cable->pBodyNodes[0],Vec3(100,100,100));
    
    // Game loop
    while( !KeyHit() && !AppTerminate() )
    {
    	if( !AppSuspended() ) // We are not in focus!
    	{
    		//Move
    		if(KeyDown(KEY_RIGHT)==1){
    			sx = sx + 0.1;
    			ex = ex + 0.1;
    		}
    		if(KeyDown(KEY_LEFT)==1){
    			sx = sx - 0.1;
    			ex = ex - 0.1;
    		}
    		PositionEntity(c,Vec3(sx,sy,sz));
    
    
    		Cable->Update();
    
    		// Update timing and world
    		UpdateAppTime();
    		UpdateWorld(AppSpeed()) ;
    
    		// Render
    		RenderFramework();
    		UpdateFramework();
    
    		//Texts
    		DrawText(10,25,"%f",(EntityPosition(Cable->pPivotStart)).X);
    
    		// Send to screen
    		Flip(0) ;
    	}
    }
    
    // Done
    return Terminate() ;
    }
    
    

  10. So, I have three trigger types:

    1: to determine the progress of player in the scene.

    2: THIS of my example, that is to activate some fx, like audio fx, post process etc...

    3: a fence to limit the car in the road, when the car over this trigger, he is brought back to road.

     

    In the car player script have a function Collide, when it collides with some trigger, is sent a menssage to c++ code(ReceiveMessage()) with the name of the trigger collided. For this, the naming convention. If it collided in the trigger type 3 for sample, is sent this message: "trigger3_4", so, the car will positioned in the last trigger1 that has been collided.

     

    In the case of Trigger2, in the second number("trigger2_x_y"), the "y", is the fx(if 1:sound x, if 2: postfx x....etc), but the first number, the "x", is need be different, cause when the c++ receive the message with the name, is stored in a array, and "x" is the index of this array.

     

    I tried explain better my problem, my english no help much...hehe

    But if need, I try explain in other way..

  11. Hi peoples...

    Im having the follow problem: I have a model called trigger2. Always that I create a new trigger2 in editor, it is called as "trigger2_x_y", where 'x' is the ID, 1,2,3,4....and 'y' is the fx that will received, that is set in own properties. I.e, if I create the first 'trigger2' in scene, with the fx set to '0', it name as "trigger2_0_0", if I create other in the scene, it is named as "trigger2_1_0", and so on.

     

    The problem is each trigger2 that I create in the scene, is add a value in the first trigger too, and not only in last trigger. If have 10 trigger in the scene, the first trigger, is named as "trigger2_0_1_3_4_5_9_5_6...."..

     

    I think that something with the global variables in the own class model. But dont know how solve this..

     

    This is the trigger code:

     

    require("scripts/class")
    local class=CreateClass(...)
    
    function class:InitDialog(grid)
    self.super:InitDialog(grid)
    group=grid:AddGroup("Tipo")
    group:AddProperty("tipofx",PROPERTY_CHOICE,"0,1,2,3,4,5,6,7,8,9,10","Tipo Fx")
    group:Expand(1)
    end
    
    function class:CreateObject(model)
    local object=self.super:CreateObject(model)
    
    local mesh=nil
    
    object.model:SetKey("tipofx","0")
    
    if(n~=nil) then n=nil end
    if(n2~=nil) then n2=nil end
    if(id~=nil) then id=nil end
    if(id2~=nil) then id2=nil end
    
    
    id=0
    id2=0
    function object:SetKey(key,value)
    	if key=='tipofx' then --overrides color setting
    		n2 = n.."_"..value
    		object.model:SetKey("name",n2)
    	end
    
    	return 1
    end
    
    
    function object:Update()
    
    	if debug==1 and mesh==nil then
    		mesh=LoadModel("abstract::pista1_models_triggers_trigger3_trigger3mesh.gmf",model)
    		model:SetShadowMode(0,1)
    		mesh:SetKey("name",model:GetKey("name"))
    	elseif debug == 0 and mesh ~= nil then 
    		mesh:Free()
    		mesh=nil
    	end
    
    	if(id2==0) then
    		n=object.model:GetKey("name")
    		n2 = n.."_"..object.model:GetKey("tipofx")
    
    		n=object.model:GetKey("name")
    		local fx=object.model:GetKey("tipofx")
    		local n2=n.."_"..fx
    		self.model:SetKey("name",n2)
    		id2=1
    	end
    end
    
    
    function object:Collision(entity,position,normal,force,speed)
    	if chave==0 then
    		Trigger()
    		chave=1	
    	end	
    end
    
    
    function object:Free(model)
    
    	if mesh~=nil and debug==0 then	
    		mesh:Free()
    		mesh=nil
    	end
    
    end
    
    
    end
    
    
    

  12. Yes, the EntityPosition(). You can also do this:

     

    
    TVec3 planetpos = EntityPosition(planet);
    TVec3 objpos = EntityPostion(obj);
    
    //x
    while(objpos.x<planetpos.x){
      MoveEntity(obj,Vec3(-1,0,0);
    }
    while(objpos.x>planetpos.x){
      MoveEntity(obj,Vec3(1,0,0);
    }
    //y
    while(objpos.y<planetpos.y){
      MoveEntity(obj,Vec3(0,-1,0);
    }
    while(objpos.y>planetpos.y){
      MoveEntity(obj,Vec3(0,1,0);
    }
    //z
    while(objpos.z<planetpos.z){
      MoveEntity(obj,Vec3(0,0,-1);
    }
    while(objpos.z>planetpos.z){
      MoveEntity(obj,Vec3(0,0,1);
    }
    
    

     

    not a good solution, but it can work. :)

  13. Yes ZioRed, I have tried this, but the problem continue =/

    I have tried model by model..

     

    I seems to be a bug in the engine.dll, only Josh can fix it.

    cool this, because now I depend this, for test the game out editor. The Josh have a preview to when will fix it?

  14. Why I use the SetWorldCullRange(), my program is crash? I update all files, and continue with StackOverflow..

    Im still with the problem with "auto hide models", and i think that this function, will solve my problem, but donk cant use. Are something worng im my code?

     

    2rgytlt.jpg

     

     

    //	====================================================================
    //	This file was generated by Leadwerks C++/LEO/BlitzMax Project Wizard
    //	Written by Rimfrost Software
    //	http://www.rimfrost.com 
    //	====================================================================
    
    #include "engine.h"
    
    int main( int argn, char* argv[] )
    {
    
    //Resolution
    int width=800,height=600;
    
    Initialize() ;
    RegisterAbstractPath("D:/Projetos/Rally");
    SetAppTitle( "Rally" ) ;
    Graphics( width, height ) ;
    AFilter() ;
    TFilter() ;
    
    // Cria FrameWork
    TFramework framework=CreateFramework();
    // Pega Layer da Camera main
    TLayer layer = GetFrameworkLayer(0);
    // Pega Camera principal(main)
    TCamera camera=GetLayerCamera(layer);
    
    // CONFIGURA O CENARIO ##################
    //Camera
    PositionEntity(camera,Vec3(-818,19,832));
    SetWorldCullRange(50,125,500);
    
    
    TVec3 camrotation=Vec3(0);
    float mx=0,my=0;
    float move=0,strafe=0.0;
    
    
    // Game loop
    while( !KeyHit() && !AppTerminate() )
    {
    	if( !AppSuspended() ) // We are not in focus!
    	{
    		//FREE LOOK
    		mx = Curve(MouseX()-GraphicsWidth()/2, mx,6);
               my = Curve(MouseY()-GraphicsHeight()/2, my,6);
               MoveMouse(GraphicsWidth()/2, GraphicsHeight()/2);               
               camrotation.X = camrotation.X+my/10.0;
               camrotation.Y = camrotation.Y-mx/10.0;
               RotateEntity(camera, camrotation);
    
    		//MOVE CAMERA
    		move   = Curve(KeyDown(KEY_W)-KeyDown(KEY_S),move,10);
    		strafe = Curve(KeyDown(KEY_D)-KeyDown(KEY_A),strafe,10);
    		MoveEntity(camera,Vec3(strafe,0,move));
    
    
    		// Update timing and world
    		UpdateAppTime();
    		UpdateWorld(AppSpeed()) ;
    
    		// Render
    		UpdateFramework();
    		RenderFramework();
    
    		// Send to screen
    		Flip(0) ;
    	}
    }
    
    // Done
    return Terminate() ;
    }
    
    
    
    

     

     

    thanks

×
×
  • Create New...