-
Posts
247 -
Joined
-
Last visited
Content Type
Blogs
Forums
Store
Gallery
Videos
Downloads
Everything posted by Charrua
-
Smoothed car drive - Leadwerks 4.5
Charrua commented on Marcousik's blog entry in Marcousik's Creations Blog
self.Tires[n]:SetOmega(self.Tires[n]:GetOmega()*Vec3(5,5,5)) --------- make the car go faster very smart! --Smoothing: if turning==0 then self.entity:SetOmega(self.entity:GetOmega()*Vec3(-1,-1,-1)) else self.entity:SetOmega(0,turning*Gas,0) end self.Axes[0]:SetOmega(self.Axes[0]:GetOmega()*Vec3(-1,-1,-1)) self.Axes[1]:SetOmega(self.Axes[1]:GetOmega()*Vec3(-1,-1,-1)) self.Axes[2]:SetOmega(self.Axes[2]:GetOmega()*Vec3(-1,-1,-1)) self.Axes[3]:SetOmega(self.Axes[3]:GetOmega()*Vec3(-1,-1,-1)) self.Axes[0]:SetVelocity(self.Axes[0]:GetVelocity()*Vec3(1,0.5,1)) self.Axes[1]:SetVelocity(self.Axes[1]:GetVelocity()*Vec3(1,0.5,1)) self.Axes[2]:SetVelocity(self.Axes[2]:GetVelocity()*Vec3(1,0.5,1)) self.Axes[3]:SetVelocity(self.Axes[3]:GetVelocity()*Vec3(1,0.5,1)) -- fake wheels update: self.Wheels[0]:SetMatrix(self.Tires[0]:GetMatrix()) self.Wheels[1]:SetMatrix(self.Tires[1]:GetMatrix()) self.Wheels[2]:SetMatrix(self.Tires[2]:GetMatrix()) self.Wheels[3]:SetMatrix(self.Tires[3]:GetMatrix()) self.Wheels[0]:SetPosition(self.PosWheels[0]+Vec3(0,self.Amortisseurs[0]:GetAngle()/6,0)) self.Wheels[1]:SetPosition(self.PosWheels[1]+Vec3(0,self.Amortisseurs[1]:GetAngle()/6,0)) self.Wheels[2]:SetPosition(self.PosWheels[2]+Vec3(0,self.Amortisseurs[2]:GetAngle()/6,0)) self.Wheels[3]:SetPosition(self.PosWheels[3]+Vec3(0,self.Amortisseurs[3]:GetAngle()/6,0)) end too much tuning on all of this constants... very nice! -
Workshop car for LE4.5 - ready to drive
Charrua commented on Marcousik's blog entry in Marcousik's Creations Blog
nice! -
Sphere is placed by math at the center of the 4 wheels, so, as you say, any shape is ok. The camera uses the orientation of the real chassis, for that reason it has this strange behavior. I still use a 100 mass car, an strength is scaled as speed rise. The chassis hits the ground and has 0 friction, I guess is better to hide it and let the fake chassis look nice and slow, perhaps I reduce the movement using some average values to reflect or simulate a more realistic one...
-
About krazy tests... video captures are so glitchy, i guess is the combination of leadwerks and the video capture sofware.. There are 4 lines of text, the first two are what is the speed aplied to the wheels and so, the estimates speed, based on diameter*PI in m/s and km/s The last two lines are based on real distance travelled (taking chassis positions each second and calclating distance, with vec3 distance to point function) I placed the chassis underground and it behaves ok, but beaware of not jump! The white sphere (is a fake chassis) is placed by hand doing an average of the position of the 4 wheels. testCar body under floor seen.avi if you set the property Hidden on the editor, then jumps are ok but, behavior is not much as realistic as it should, when you stop, the chassis seems to do a pendulus movement.. testCar body under floor hiden.mp4 now, the following two test are with the cassis in the correct place, seen/not seen. When chassis is correctly placed, as marcosuik says it tends to touch the floor and seems to try to fly I am using strength scaled (increased) by car speed. testCar body avobe seen.avi testCar body avobe hidden.avi Juan
-
Thanks, I will try it, I was applying scaled strength based on speed in my last (not published still) tests.. Also doing not so logical tests :), but with good resultsresults
-
Now, I wrote a single script that creates suspension, steer and traction You have to create the chassis, 4 wheels, set this script to each one of the wheels and then paly with the configurable parameters. Enjoy: --[[ Autor Juan Ignacio Odriozola (charrua) Purpose: A script that facilitates the making of a simple car all you need is a chassis and 4 wheels assing this scrip to each wheel and set the object chassis then adjust some of the configurable parameters Parent: chassis entity : wheel 3 joints and 2 auxiliary entities are created the chain is: Parent Slider Pivot Hinge Pivot Hinge chassis -suspensionJoint- suspensionPivot -steerJoint- steerPivot -wheelJoint- wheel suspension uses pin 010 (Y axis) steer uses pin 010 (Y axis) wheel pin (must be set depends of wheel orientation) up/down keys are defaults for forward and backward left/right keys are defaults for steer left/right space key is default for brakes steer velocity and start/end angle must be set suspension lenght must be set wheel friction must be set steerAngle set both limits to +/- steerAngle/2 if no key (left/right) is pressed then, target angle is 0 : straight suspensionLenght set both limits to +/- suspensionLength/2 and target distance is set to 0 suspension strength defaults to 1000 which is too much strenght for a light weight car (20 of mass) and not to much for a 200 car of mass each joint is created with a mass of 1, which should be taking into accoung (so for a 4 wheels car, you have a mass of 8 on the 8 joints). there are so many other parameters that may be adjusted: Spring, Strength, Stiffness ... not too much documented :) ]]-- Script.currspeed = 0 Script.chassis = nil--Entity "chassis" Script.pin = Vec3(0,0,1) --Vec3 "wheel Pin" Script.motorspeed=500--float "max motor speed" Script.velcontrolled=false--bool "velControl" Script.suspensionLength=0.2--float "suspension" Script.steerAngle=90--float "steer angle" Script.steerSpeed=100--float "steer velocity" Script.friction=1--float "wheel friction" Script.steerPivot=nil Script.suspensionPivot=nil Script.steerJoint=nil Script.suspensionJoint=nil Script.wheelJoint=nil function Script:Start() local pos = self.entity:GetPosition(false) --true for global if self.chassis ~= nil then self.suspensionPivot = Pivot:Create() self.suspensionPivot:SetPosition(pos) self.suspensionPivot:SetMass(1) self.suspensionPivot:SetCollisionType(Collision.None) self.steerPivot = Pivot:Create() self.steerPivot:SetPosition(pos) self.steerPivot:SetMass(1) self.steerPivot:SetCollisionType(Collision.None) --joints creation self.suspensionJoint = Joint:Slider(pos.x, pos.y, pos.z, 0, 1, 0, self.chassis, self.suspensionPivot) self.steerJoint = Joint:Hinge(pos.x, pos.y, pos.z, 0, -1, 0, self.suspensionPivot, self.steerPivot) self.wheelJoint = Joint:Hinge(pos.x, pos.y, pos.z, self.pin.x, self.pin.y, self.pin.z, self.steerPivot, self.entity) --suspension self.suspensionJoint:EnableLimits() self.suspensionJoint:SetLimits(-self.suspensionLength/2,self.suspensionLength/2) --steerAngle=0 means no steer self.suspensionJoint:SetTargetAngle(0) --at the middle self.suspensionJoint:SetMotorSpeed(1) -- 1 m/s self.suspensionJoint:SetStrength(100) --defatul is 1000 self.suspensionJoint:EnableMotor() --steer self.steerJoint:EnableLimits() self.steerJoint:SetLimits(-self.steerAngle/2,self.steerAngle/2) --steerAngle=0 means no steer self.steerJoint:SetMotorSpeed(self.steerSpeed) self.steerJoint:EnableMotor() --wheel self.entity:SetFriction(self.friction, self.friction) else Debug:Error("no chassis assigned") end end function Script:setMotorSpeed(speed) if self.velcontrolled then --System:Print("setMotorSpeed: "..speed) self.currspeed = speed if speed~=0 then self.wheelJoint:EnableMotor() end self.wheelJoint:SetMotorSpeed(self.currspeed) end end function Script:UpdateWorld() if self.motorspeed>0 then self.wheelJoint:SetAngle(self.wheelJoint:GetAngle()+100) else self.wheelJoint:SetAngle(self.wheelJoint:GetAngle()-100) end if App.window:KeyDown(Key.Space) then self:setMotorSpeed(0) end if self.velcontrolled then if App.window:KeyDown(Key.Up) then self.currspeed = self.currspeed + 10 if self.currspeed>self.motorspeed then self.currspeed=self.motorspeed end if self.currspeed == 10 then self.wheelJoint:EnableMotor() end self.wheelJoint:SetMotorSpeed(self.currspeed) end if App.window:KeyDown(Key.Down) then self.currspeed = self.currspeed - 10 if self.currspeed<-self.motorspeed then self.currspeed=-self.motorspeed end self.wheelJoint:SetMotorSpeed(self.currspeed) end end if self.steerAngle>0 then local direction=0 if App.window:KeyDown(Key.Left) then direction=-self.steerAngle/2 end if App.window:KeyDown(Key.Right) then direction=self.steerAngle/2 end self.steerJoint:SetAngle(direction) else self.steerJoint:SetAngle(0) end end In the other maps i was using a box as a floor to which I set the desired friction, testing this new script i use a terrain and have to figure it out how to set the friction to the terrain... Did some searches and ended with: local n for n=0,self.world:CountEntities()-1 do local entity = self.world:GetEntity(n) if entity:GetClassName()=="Terrain" then terrain = entity System:Print("terrain found!") terrain:SetFriction(10,10) break end end insert this in the app.lua (after load map) and then you can play with terrain friction, the video shows how the car behaves with the defaul terrain friction and then whit a friction of 10,10 Always learning something new A word about some parameters: If you are using a hinge, when you specity speed (SetMotorSpeed) the number means degrees per second. So if you use 3600 as max speed you get 10 revoluions per second. If your tire has, 64cm then d*pi aprox 2 meters per revolution, 10 revolutions per secon aprox 20 meters per second... and if you are lucky 72Km/h If you are using a slider, then speed is un meters per second. Other parameter which is very important is the hinge/slider "pin" which is a vector that tells the direction of movement of the slider or over which plane de hinges open/close For a common door, we need to use the Y axis, so the pin is 0,1,0 I use this pin for the suspension and for the steer but for this script, you must tell the traction pin, which sould be 1,0,0 or 0,0,1 depending on the orientation of your tires If your tires are not facing X nor Z axis, then you have to do some math to get the proper x,z component of the pin In the script I use a Strenght of 100, instead of the 1000 which is default, my car is light weight : 5 + 4*3 = 17 of Mass chassis has 5, each wheel has 1 and the 2 auxiliary pivots has 1 each one whith a friction of 10 on each tire and with a friction of 10 on the terrain looks ok for me (better than I spected at first). Juan
-
If you get lost, you may PM me in spanish, but I do prefere to continue the therad in english, so, it keeps being usefull for the rest of the members. As you may know from my username, I'm from Uruguay, Montevideo, the southest Capital of South America Charruas was the ones that habit these lands before european came. Juan
- 8 comments
-
- 1
-
- rope bridge
- physics
- (and 5 more)
-
look in my previous blog: simple car, in it you have all that you need. look at the wheel.lua script and see how do I control the velocity and in steer.lua how do I control steer. read it carefully, try to learn how the whole project works.. and you will find what you need. The zip file included on the blog has the entire project which is basen on Lua exclusively so any Leadwerks user might use it.
- 8 comments
-
- 1
-
- rope bridge
- physics
- (and 5 more)
-
yes, for a tire you have to place the hinge at the same position of the tire (which is it's center also)
- 8 comments
-
- 1
-
- rope bridge
- physics
- (and 5 more)
-
bisagra = Joint:Hinge( 0, 0, 0, 0, 1, 0, self.puerta, self.entity ) you are creating the joint at 0,0,0 so it will be at this position (bisagra = Joint:Hinge( 0, 0, 0, 0, 1, 0, self.puerta, self.entity ) you have to place the hinge in the correct position, to the left of the door. If you decide to create the hinge by code, then, look on the editor whic are the x,y,z world coodinates at the left of the door and use these values on your code.
- 8 comments
-
- rope bridge
- physics
- (and 5 more)
-
Recently i posted a simple car made with joints without too much explanations... so What is a joint? This video shows joints in action. At the end, the stand alone executable and the complete project. The following text and figure is from the "ode-latest-userguide", figures are also form the JV-ODE documentation: In real life a joint is something like a hinge, that is used to connect two objects. It is a relationship that is enforced between two bodies so that they can only have certain positions and orientations relative to each other. This relationship is called a constraint, the words joint and constraint are often used interchangeably. The figure shows three different constraint types. The first is a ball and socket joint that constraints the “ball” of one body to be in the same location as the “socket” of another body. The second is a hinge joint that constraints the two parts of the hinge to be in the same location and to line up along the hinge axle. The third is a slider joint that constraints the “piston” and “socket” to line up, and additionally constraints the two bodies to have the same orientation. Each time the integrator takes a step all the joints are allowed to apply constraint forces to the bodies they affect. These forces are calculated such that the bodies move in such a way to preserve all the joint relationships. Each joint has a number of parameters controlling its geometry. An example is the position of the balland- socket point for a ball-and-socket joint. The functions to set joint parameters all take global coordinates, not body-relative coordinates. A consequence of this is that the rigid bodies that a joint connects must be positioned correctly before the joint is attached. Figure: types of joints The "Integrator step" is the part of the physics engine that does all the calculations. Based on the current state, force applied, constrain parameters, collisions etc... recalculates the next position and rotation of every affected physical obejct. Leadwerks then, does the render of the objects acordingly to it's new positions, or that is what is supposed to do... (Josh should correct me if I'm wrong). A joint normally is placed between two objects, one is called Parent and the other Child. The child should be NULL, and in this case the joint is between one body and the world or scene. In the case of a door, you need a Door and a Frame, the Frame should be the Parent body, the Door the child body. In real life you have to decide where the Hinge (or more than one) will be placed and use some screws to attach both parts of the hinge to the frame and the door. In software, things are practically the same In other words, we have to have 3 things clear: Who is the parent and where it should be positioned and oriented. Who is the child and where it should be poitioned and oriented. Which type of joint you need, where it should be positioned and oriented. Normally we create and place the two bodies first and then, at joint creation we say where the joint will be and how it should be oriented, who the parent is and who child is, if any. After that, joints normally has some other properties that should be adjusted, used, controlled, limited, enabled... etc, depending on the joint type. Joints have two "limits": If the joint is a Hinge, the limits are the Start Angle and End Angle "the door should turn". If the joint is a Slider, the limits are the Start Position and End Position the piston should extend. If the joint is a Ball, the limits are the cone angle and twist or torsion... keep reading Joints (hinge and slider) should have a "motor" if not, as a normal door, we need external forces to "open the door", if we place a door on a frame attached with hinges and the door has no lock at all, then the wind should open/close it, or some body that collides with the door should move it. As we use a hinge, the door do not fall, do not take an upward motion, the motion is well known and constrainded tho the clasic movement we all know. But if, for instance we have a "motorized door" then the open/close operation is started in some way (press of a button?) and a motor does the job. Normally it stops automatically, because there are end-run switches or the like installed and working for us. A sofware motorized joint is exactly that, we set where we want the joint go (setTargetAngle), and start a motor (enableMotor). Ball Joint A ball is used when we need a "cone" movement freedom, think that you have a rope attached at the roof of your room and you hang a box on it. If the rope is made of a rigid material, the box should made a pendulum movement not so large and probably the box orientations should not change too much. How much we let the rope to move is dictated by the first limit and how much the object attached should change orientation (twist/torsion) is dictated by the second limit. A rope is a nice looking example, all you have to do is place N cubes (shape is not important) and place ball joints in the middle of each pair. You may have the first box joined to the world (attached to a fixed 3d position) and then a link of bodies and ball joints: Joint N has body N as parent and body N+1 as child Leadwerks came with a simple ball.lua script: function Script:Start() local pos = self.entity:GetPosition(true) self.joint = Joint:Ball(pos.x, pos.y, pos.z, self.entity, self.entity:GetParent()) self.joint:SetFriction(10) self.entity:SetDamping(0,0) end If you have a chain of parented objetcts, then you may set this script and you have a rope build with a few clicks of your mouse on the editor. Procedure: Create some boxes, set prop collision and a mass not zero (1 perhaps), place then in a vertical row somewhat separated. In the editor drag the second box to the first, the third to the second building a hierachy (parent/child relationship) Select all (one by one with ctrl click on each box) and then apply the ball script. Voila! You have a rope with no limits: cone angle is the maximum the engine lets you to be and the same for torsion. Collide the rope with some object or, place the boxes horizontally (instead of vetically) and let gravity do it's job. I made another ball script: ballEnhaced: Script.parent = nil--Entity "Parent" Script.child = nil--Entity "Child" Script.useLimits=false--bool "Use limits" Script.coneAngle = 45--Float "Cone Angle" Script.torsion = 45--Float "Torsion" Script.hide = true--bool "Hide entity" function Script:Start() local pos = self.entity:GetPosition(true) if self.parent~=nil then self.joint = Joint:Ball(pos.x, pos.y, pos.z, self.parent, self.child) self.joint:SetLimits(self.coneAngle, self.torsion) if self.useLimits then self.joint:EnableLimits() System:Print("limits:"..self.coneAngle..", "..self.torsion) end if self.hide then self.entity:Hide() end end end if using this script, you have to create a pivot or box (collision type: none, and no mass) and tell the script ho the parent is and ho the child is, if no child, then the parent body will be attached to the environement, fixed at this 3d point. In the map included in this blog there are two ropes, one made with the leadwerks ball.lua and one with the ballEnhaced.lua script, in this script you may tell how to constrain the ball cone anlgle and trosion. Look the video, and you will see the difference on how the cubes behave when hitted by the car. A rope suspension bridge should be made with both ends attached to the world and a double chain of joints... doing two unions between each part of the brige. It's nice so see the car passing over it! The attached video shows at first the car passing over the bridge... the mass of the car is very little, if not, the joints get broken.. as always there are some other things to consider. Hinje Joint As I used a hinge for some explanation, i guess there is not to much to say here, I use some hinges for doors in the map attached and also used them for the steer and wheels of the car. One door have a motor and the other not, so the second one moves as the car collides it. I wrote two scripts: hingeEnhaced.lua Script.parent = nil --entity "parent" Script.child = nil --entity "hild" Script.hide = true--bool "Hide entity" Script.pin = Vec3(0,0,1) --Vec3 "Hinge Pin" Script.limitsenabled=false--bool "Enable limits" Script.limits = Vec2(-45,45) --Vec2 "Limits" Script.friction = 0--float "Friction" function Script:Start() local pos = self.entity:GetPosition(true) if self.parent~=nil then self.joint = Joint:Hinge(pos.x, pos.y, pos.z, self.pin.x, self.pin.y, self.pin.z, self.parent, self.child) if self.limitsenabled then self.joint:EnableLimits() end self.joint:SetLimits(self.limits.x,self.limits.y) self.joint:SetFriction(self.friction) self.entity:SetDamping(0,0) if self.hide then self.entity:Hide() end end end As in the case of a ball joint, with this script you may set parent, child and limits hingeMotorized.lua Script.parent = nil --entity "parent" Script.child = nil --entity "hild" Script.hide = true--bool "Hide entity" Script.pin = Vec3(0,0,1) --Vec3 "Hinge Pin" Script.limitsenabled=false--bool "Enable limits" Script.limits = Vec2(-45,45) --Vec2 "Limits" Script.tOpenClose = 15 --Int "Open/Close time" Script.movespeed = 60 --Int "Speed" Script.startTime = 0 Script.action = 1 --1 open, 0 close function Script:Start() local pos = self.entity:GetPosition(true) if self.parent~=nil then self.joint = Joint:Hinge(pos.x, pos.y, pos.z, self.pin.x, self.pin.y, self.pin.z, self.parent, self.child) if self.limitsenabled then self.joint:EnableLimits() end self.joint:SetLimits(self.limits.x,self.limits.y) self.joint:SetTargetAngle(self.limits.x) self.joint:EnableMotor() self.startTime = Time:GetCurrent() self.joint:SetMotorSpeed(self.movespeed) if self.hide then self.entity:Hide() end end end function Script:UpdatePhysics() local time_ = Time:GetCurrent() if time_ - self.startTime > self.tOpenClose*1000 then self.action = 1-self.action --toggle action if self.action == 1 then self.joint:SetTargetAngle(self.limits.x) else self.joint:SetTargetAngle(self.limits.y) end self.startTime = Time:GetCurrent() end end This scripts creates the joint, then set a target angle, enables the motor and apply a velocity, so the "door" starts going to the first limit. After the tOpenClose time, the variable action is toggled and based on it the TargetAngle will be first limit or second limit, in this way, the door continously open and then close after tOpenClose time Slider Joint For a slider joint, in this map i wrote one script: sliderMotorized.lua Script.child = nil --entity "hild" Script.hide = true--bool "Hide entity" Script.pin = Vec3(0,0,1) --Vec3 "Hinge Pin" ScrScript.parent = nil --entity "parent" ipt.limitsenabled=false--bool "Enable limits" Script.limits = Vec2(-45,45) --Vec2 "Limits" Script.tOpenClose = 15 --Int "Open/Close time" Script.movespeed = 60 --Int "Speed" Script.startTime = 0 Script.action = 1 --1 open, 0 close function Script:Start() local pos = self.entity:GetPosition(true) if self.parent~=nil then self.joint = Joint:Slider(pos.x, pos.y, pos.z, self.pin.x, self.pin.y, self.pin.z, self.parent, self.child) if self.limitsenabled then self.joint:EnableLimits() end self.joint:SetLimits(self.limits.x,self.limits.y) self.joint:SetTargetAngle(self.limits.x) self.joint:EnableMotor() self.startTime = Time:GetCurrent() self.joint:SetMotorSpeed(self.movespeed) if self.hide then self.entity:Hide() end end end function Script:UpdatePhysics() local time_ = Time:GetCurrent() if time_ - self.startTime > self.tOpenClose*1000 then self.action = 1-self.action --toggle action if self.action == 1 then self.joint:SetTargetAngle(self.limits.x) else self.joint:SetTargetAngle(self.limits.y) end self.startTime = Time:GetCurrent() end end This script is 99% the same as the hingeMotorized.lua, the only difference is that a slider joint is created instead of a hinge joint. Note that the limis are not angles, they are offsets from the initial position of the plataform. Stand alone executable: jointsworldDistro.zip Project: jointsworldProject.zip Enjoy Juan
- 8 comments
-
- 6
-
- rope bridge
- physics
- (and 5 more)
-
you may also have to change th working directory... sooner or later Juan
-
Here there is a way of making a simple car based on hinges This is not a tutorial, is just simply a stating point for the ones that want/like to play arround physics and hinges... I included the entire project and the distribution executable to test the scripts so, you have as I say a starting point and just that, hpe it helps someone This is the editor view and the initial placement of the parts needed Basically I made 3 scripts physicsProperties.lua wheel.lua steer.lua First you have to create and place the car body or chassis, 4 wheels and 6 auxiliary pivots/ or any brush you like (a cube is fine) for the hinges 4 of the auxiliary entities are for the wheels hinges and 2 for the wheels steer. Place the wheel hinge and steer centered with the wheel. After that you may set some script parameters: Wheel scritp: Basically, the position of the entity script holder is used to create a hinge between the "parent" and the "child" you choose (in the picture above: between the auxiliary entity SteerFL and the WheelFL) If vel control is checked then, a motor is enabled for that hinge and keys Up/Down are used to increase/decrease speed If vel control is not cheched, no motor is enabled and the wheel is free to run Be carefull whit the Hinge Pin, which dictates the axis over which the wheel will rotate, in this case I used X axis, but if you use other pieces direction/alignement you should adjust this values. Steer script: The steer hinge is used to turn the wheel to handle car heading, so the pin is the Y axis Limits and Motor are needed to control the steer Limits is for how much the steer will turn right/left using the default keys left/right arrow When you press left or ritght key, the right limit will be set as the hinge angle and the hinge will try to reach this angle at the "steer speed", the same, but whit the left limit happen if you press the left key. physicsProperties just let you adjust the friction of the wheels and or the floor Script.sfrict=0--float "static friction" Script.kfrict=0--float "kinetic friction" function Script:Start() System:Print("phy properties start") self.entity:SetFriction(self.sfrict, self.kfrict) end so simple, and in the editor it looks: Here is a hand drawing of how scripts, objects, parent/child are connected Here is the wheel script Script.currspeed = 0 Script.parent = nil--Entity "Parent" Script.child = nil--Entity "Child" Script.pin = Vec3(0,0,1) --Vec3 "Hinge Pin" Script.motorspeed=500--float "Motor speed" Script.velcontrolled=false--bool "velControl" function Script:Start() System:Print("wheel start") self.entity:Hide() local pos = self.entity:GetPosition(false) --true for global if self.child ~= nil then if self.parent ~= nil then self.joint = Joint:Hinge(pos.x, pos.y, pos.z, self.pin.x, self.pin.y, self.pin.z, self.child, self.parent) else Debug:Error("no parent assigned") end else Debug:Error("no child assigned") end end function Script:setMotorSpeed(speed) if self.velcontrolled then System:Print("setMotorSpeed: "..speed) self.currspeed = speed if speed~=0 then self.joint:EnableMotor() end self.joint:SetMotorSpeed(self.currspeed) end end function Script:UpdateWorld() if self.motorspeed>0 then self.joint:SetAngle(self.joint:GetAngle()+100) else self.joint:SetAngle(self.joint:GetAngle()-100) end if App.window:KeyDown(Key.Space) then self:setMotorSpeed(0) end if self.velcontrolled then if App.window:KeyDown(Key.Up) then self.currspeed = self.currspeed + 10 if self.currspeed>self.motorspeed then self.currspeed=self.motorspeed end if self.currspeed == 10 then self.joint:EnableMotor() end self.joint:SetMotorSpeed(self.currspeed) end if App.window:KeyDown(Key.Down) then self.currspeed = self.currspeed - 10 if self.currspeed<-self.motorspeed then self.currspeed=-self.motorspeed end self.joint:SetMotorSpeed(self.currspeed) end end end Here is the steer scritp Script.parent = nil--Entity "Parent" Script.child = nil--Entity "Child" Script.pin = Vec3(0,1,0) --Vec3 "Hinge Pin" Script.useLimits=false--bool "use limits" Script.limits = Vec2(-45,45) --Vec2 "Limits" Script.useMotor=flase--bool "use motor" Script.motorspeed=50--float "Steer speed" function Script:Start() System:Print("steer start") if self.child == nil then Debug:Error("No child assigned.") end if self.parent == nil then Debug:Error("No parent assigned.") end self.entity:Hide() local pos = self.entity:GetPosition() self.joint = Joint:Hinge(pos.x, pos.y, pos.z, self.pin.x, self.pin.y, self.pin.z, self.child, self.parent) if self.useLimits then self.joint:EnableLimits() self.joint:SetLimits(self.limits.x,self.limits.y) end if self.useMotor then self.joint:SetMotorSpeed(self.motorspeed) self.joint:EnableMotor() end end function Script:UpdateWorld() local direction=0 if App.window:KeyDown(Key.Left) then direction=self.limits.x end if App.window:KeyDown(Key.Right) then direction=self.limits.y end self.joint:SetAngle(direction) end here the distro: simpleCarDistro.zip here the project: simpleCar.zip and here a video... enjoy Juan
-
wrong app path from cpp and ok from leadwerks editor
Charrua replied to Charrua's topic in General Discussion
i did some searches, without success, now, looking for "working directory" found a Roland post and now all is fine! thanks Juan -
I was using Leadwerks 4.4, recently i upgraded to latest beta and installed visual studio 2017 I get to have working a project i'been on (mBot simulator) with some usual mistakes in the process, all of mine, over and over again... But, i started a blank project to test some gui related things... and i found that all the references to files do not have the app name in the filepath If i build the debug/release version it builds ok, if i then run or debug from the leadwerks editor every thing is fine, but if i run from visual studio the app crashes looking at the console i found that the lua scripts are not loaded because the path do not include the project's name, and when as I said, run from leadwerks etitor, the output throws the correct paths... guess i have some setting missing... any idea? aplication name: pruebasGui thats the console from visual studio: Error: No debugger hostname supplied in command line. Initializing OpenGL graphics driver... OpenGL version 450 GLSL version 450 Device: GeForce 840M/PCIe/SSE2 Loading shader "C:/Users/notebook/Documents/Leadwerks/Projects/Shaders/Drawing/drawprimitive.shader"... Error: Failed to load shader "C:/Users/notebook/Documents/Leadwerks/Projects/Shaders/Drawing/drawprimitive.shader" Loading component "C:/Users/notebook/Documents/Leadwerks/Projects/Scripts/GUI/Panel.lua..." Initializing Lua... Warning: Lua sandboxing disabled. Executing file "C:/Users/notebook/Documents/Leadwerks/Projects/Scripts/Error.lua" Error: Failed to read file "C:/Users/notebook/Documents/Leadwerks/Projects/Scripts/Error.lua". Failed to load component "C:/Users/notebook/Documents/Leadwerks/Projects/Scripts/GUI/Panel.lua" Loading component "C:/Users/notebook/Documents/Leadwerks/Projects/Scripts/GUI/Button.lua..." Failed to load component "C:/Users/notebook/Documents/Leadwerks/Projects/Scripts/GUI/Button.lua" that's the output from leadwerks editor: Executing "C:\Users\notebook\Documents\Leadwerks\Projects\pruebasGui\pruebasGui.debug.exe"... Initializing Lua... Lua sandboxing enabled. Executing file "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Scripts/Error.lua" Successfully connected to debugger. Initializing OpenGL graphics driver... OpenGL version 450 GLSL version 450 Device: GeForce 840M/PCIe/SSE2 Loading shader "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Shaders/Drawing/drawprimitive.shader"... Loading component "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Scripts/GUI/Panel.lua..." Executing file "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Scripts/GUI/Panel.lua" Loading font "C:/WINDOWS/Fonts/Arial.ttf"... Loading component "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Scripts/GUI/Button.lua..." Executing file "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Scripts/GUI/Button.lua" Loading shader "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Shaders/Drawing/drawtext.shader"... Deleting script "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Scripts/GUI/Button.lua" Loading component "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Scripts/GUI/Button.lua..." Executing file "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Scripts/GUI/Button.lua" Loading shader "C:/Users/notebook/Documents/Leadwerks/Projects/pruebasGui/Shaders/Drawing/drawimage.shader"... event queue peek widget action! butt1 pressed Process Complete. than's in advance Juan
-
thank's I test the panel thing as GrozenDev suggested and works! but.. always a but i found other problem, not related with the gui itself.., it's related to latest beta, visual studio 2017.. don't know exactly ... will see
-
thank's, i have been doing some trials... without much success trying to get events and objetcts from cpp created lua side... i will read and try what you posted here... and but... no one answer... seems to be a black hole on this topic hope your blog bring to me some light at the end of the tunnel Juan
-
Omg, should I switch links.. https://drive.google.com/file/d/1rD2J0IMv8yju-4eIAve84Sp2Rz0XF9Bl/view?usp=drivesdk Hope not this time sorry, i did it again... here is the correct installer: https://drive.google.com/open?id=1rD2J0IMv8yju-4eIAve84Sp2Rz0XF9Bl Thanks
- 12 replies
-
- 1
-
- robot car simulator
- scratch
-
(and 1 more)
Tagged with:
-
so far, so long... time to do an update a video showing the bot finding the way out of a maze.. https://youtu.be/-sOQDLpiigQ for this algorithm to work, the ultrasonic sensor and the linefollower sensor were re-positioned, thing that is easily done using the gui, as loading a new floor and/or maze. another simple test of the on-board led's the installer: https://drive.google.com/open?id=1rD2J0IMv8yju-4eIAve84Sp2Rz0XF9Bl the new look: kind regards Juan
- 12 replies
-
- 2
-
- robot car simulator
- scratch
-
(and 1 more)
Tagged with:
-
gui seems to stop working if I press scape, menu appears but do not react to mosue clicks.. (testing only a lua project) some other old joints/vehicle scripts of mine seems to not work as it did also :(, guess i have to wait some time
-
Hi Yue, nice to see you arround , very good models, congrats! You may use a slider joint to move up and down the lift part, i used them somewhat when doing some tests: I also use blitz3d some years ago with ODE, my art skill is 0, just cubes but here you may see what I've done: https://sites.google.com/site/odriozolajuanignacio/juanodriozola/blitz3d (Utility cars is at the bottom of the page) And here with Leadwerks: and some videos showing it in action As a starting point you may look at "SlidingDoor.lua" in "Scripts\Objects\Doors" to see an example of a sliding joint If you need some help, ask or PM me, in that case you know, you can use Spanish But I do like, if possible, continue here, just in case, it would be helpful for some one else here. Juan
-
Leadwerks Game Engine 5 is Coming
Charrua commented on Josh's blog entry in Ultra Software Company Blog
I received a renew some days earlier, supposed i'll be informed of a new debit, but instead i have to re do the payment, no problem at all. -
As the documentation is in Spanish… English will come soon, but mine is very elemental in the zip file will find: mBot folder: the executable vcredist_x86.exe if needed a couple of sb2 scripts: line follower and obstacle avoidance vspe: virtual serial port emulator, optional, if you need it to link scratch with the simulator (another way of linking the simulator with scratch is using a couple of FTDI modules wired one with each other Here is some basic explanation In the mBot folder you will find a couple of sub-folders called “pisos” and “laberintos” : floors and mazes. Any jpg image of 512x512 pixels can be added to the “pisos” folder and used as a mat on the 3D scene of the simulator, some examples are inside the folder for you to use. The mat will have 4m x 4m so one pixel is about 0.78 cm, i recommend the use of at least 4 pixels thick lines if you plan to build a track for the mBot to follow. In the “laberitnos” folder, there are text files with a elemental draw of the walls of the mazes: 40x40 characters each non “space” character will build a cube of 10x10x10 centimeters so a 4m x 4m maze could be built. About the first 3 lines of the text file they must contain 3 numbers, one on each first line: x position in the range 1 .. 40 column in the maze where mBot will start positioned second line, y position in the range 1 .. 40 line in the maze where mBot will start positioned third starting forward angle of mBot, 0=North (?), heading away from us, 90 means going right, 180 approaching us, 270 going to the left. Any integer from 1 to 359 may be written. If you do not link scratch with my simulator, you may select “continuar” in the first screen and use some keys to move the mBot manually and to move the camera which always look to the mBot. Keys A/Z will increase/decrease Left motor speed by 25, Up/Down arrow does the same with the Right motor Space will stop both motors Left arrow will give 50 of speed to both motors and right arrow -50 (reverse) to both motors With keypad keys you can control the camera position 5 move camera to default position 30 cm above and 40 cm behind 4,6 turn camera position clockwise/counter clockwise 8,2 rise/lower the camera 7,9 zoom in, out to reach the first screen (3 options menu) you have to press ESCAPE key if you select “Config” to select a floor and/or a maze, one, other or both and some other options like kind of power 6V, 3.7V, serial communication port, some optionally texts on screen like motors speed, line followers state, ultrasonic sensor reading… On the “Escenarios” Tab, you will have a couple of list boxes with the files on the “pisos” and “laberintos” folders, the included ones and the ones you create “pantalla” tab will let you choose screen resolution, I recommend some half width resolution so if you hide the “scene” on scratch you may have scratch and mBot simulator side by side. enjoy Juan
- 12 replies
-
- 1
-
- robot car simulator
- scratch
-
(and 1 more)
Tagged with:
-
Hi this is the first release of my mBot simulator https://www.dropbox.com/s/yoao21cieviitun/emulador mBot.zip?dl=0 documentation is in spanish https://www.dropbox.com/s/9z5wtvrfa17tt3o/guía de usuario.pdf?dl=0 in the zip file there is a folder "mBot" with the executable and a couple of subfolders "pisos" : floors "laberintos" : mazes in which some .jpg for floors and text files for defining mazes can be added to the sample ones. also there is the vcredist_x86.exe and an aplication VSPE to emulate pairs of serial ports to link the simulator with the mBot scratch sofware, and a couple of .sb2 (scratch scripts files) to test the scratch-simulator behavior. would be good to me to know if someone can execute the exe file and with what issues if any and in which platform if possible and if you have some experience with mBot and the simulator is of any interest, better! play with it enjoy Juan
- 12 replies
-
- robot car simulator
- scratch
-
(and 1 more)
Tagged with:
-
i made this tri-wheel vehicle some years ago... with hinges and a couple of lua scripts i know that vehicle is much nice than this... but is another option, here a tri and a quad wheel hinge made vehicles last month i revised and tested again those scrips on my mBot simulator and still works correctly https://www.leadwerks.com/community/topic/16695-mbot-simulator/ Juan