DanceTweety Posted March 22, 2014 Author Share Posted March 22, 2014 This is the example of how to do it but it is using a child box make in the script it self. I want to us the child box as a motor so need a box where a can put the motor script in. So how would I us a allready existing box in the Parenting script? self.entity = Model:Box() local child = Model:Box(1,1,1) child:SetParent(self.entity) child:SetColor(1.0,0.0,0.0) child:SetPosition(2,-2,0) child = Model:Box(1,1,1) child:SetParent(self.entity) child:SetColor(0.0,1.0,0.0) child:SetPosition(-2,-2,0) return true Quote Link to comment Share on other sites More sharing options...
xtreampb Posted March 22, 2014 Share Posted March 22, 2014 in your script for the motor, in the start function, self.entity:setParent(--[[entity for your boat]]--). this is eaiser to do in the editor. in the scene tab, click and drag your motor on top of your boat, you should see a plus or minus icon appear to the left of your boat and the motor is now offset and directly below your boat. It is now parented, congratulations. Quote bool Life() { while(death=false) { if(death==true) return death; } } I have found the secret to infinite life Did I help you out? Like my post! Link to comment Share on other sites More sharing options...
DanceTweety Posted March 23, 2014 Author Share Posted March 23, 2014 I did that to. Was one of the first things I tried. But the motor simply takes of even though it is in boat in the scene tab. That is why I tried the script with the hinge you see at top of this post. Quote Link to comment Share on other sites More sharing options...
DanceTweety Posted March 29, 2014 Author Share Posted March 29, 2014 Thanks for people that try to help. Was not much that worked but I figured it out my self in the end. This is how the code looks right now handy to know maybe for others: Script.enabled = true --bool "Enabled" Script.gravity = false --bool "Gravity" Script.movespeed = 1 --Define self.movespeed Script.originPosition = nil --Define self.originPosition Script.currentPosition = nil --Define self.currentPosition Script.oldMass = nil --Define self.oldMass Script.window = Window:GetCurrent() --Define self.window Script.move = Vec3(0,0,0) --Define self.move Script.rotation = "" --Define self.rotation Script.ry = 0 --Define self.ry Script.speed = "" --Define self.speed function Script:Start() self.originPosition = self.entity:GetPosition() --Get position of object self.oldMass = self.entity:GetMass() --Get mass of object if self.entity:GetShadowMode()>0 then self.entity:SetShadowMode(2)--Light.Dynamic end if self.enabled then if self.entity:GetMass() == 0 then --Get mass and check if bigger then 0 Debug:Error("Entity mass must be greater than zero.") end else self.entity:SetMass(0) end self.entity:SetGravityMode(self.gravity) --Set gravity to false self.entity:SetFriction(0,1) --Set Friction self.move = Vec3(0,0,0) --Set self.move to vector end function Script:UpdatePhysics() --Loop to update Physics self.move = Vec3(0,0,0) local movespeed = self.movespeed --Set movespeed to self.movespeed self.rotation = self.entity:GetRotation():ToString() --Set self.rotation and make it a string (else it is userdata and will not work) self.ry = string.sub(self.rotation,11,15) --Set self.ry with y of rotation (if cuts of x and z) self.ry = tonumber(self.ry) --Set self.ry to be a number self.ry = math.ceil(self.ry) --Set self.ry to be a round number local inRadians = math.rad(self.ry) --Convert degrees to radians if (self.window:KeyDown(Key.Up)) then self.move.x = -1 * movespeed * math.cos(inRadians) * Time:GetSpeed() end --Look if upper arrow key is pressed and Set value in selfmove.x (x-axis) if (self.window:KeyDown(Key.Up)) then self.move.z = movespeed * math.sin(inRadians) * Time:GetSpeed() end --Look if upper arrow key is pressed and Set value in selfmove.z (z-axis) if (self.window:KeyDown(Key.Down)) then self.move.x = movespeed * math.cos(inRadians) * Time:GetSpeed() end --Look if lower arrow key is pressed and Set value in selfmove.x (x-axis) if (self.window:KeyDown(Key.Down)) then self.move.z = -1 * movespeed * math.sin(inRadians) * Time:GetSpeed() end --Look if lower arrow key is pressed and Set value in selfmove.z (z-axis) if (self.window:KeyDown(Key.Right)) then self.move.y= movespeed * Time:GetSpeed() end --Look if right arrow key is pressed and Set value in selfmove.y (y-axis rotation) if (self.window:KeyDown(Key.Left)) then self.move.y= -1 * movespeed * Time:GetSpeed() end --Look if left arrow key is pressed and Set value in selfmove.y (y-axis rotation) self.entity:AddForce(self.move.x,0,0) --AddForce with the self.move.x value on x-axis self.entity:AddForce(0,0,self.move.z) --AddForce with the self.move.z value on z-axis self.entity:AddTorque(0,self.move.y*70,0) --AddTorque with the self.move.y value on y-axis (rotation) Time:Update() --Update Time value end function Script:PostRender() --Function to print on game screen local context=Context:GetCurrent() context:SetBlendMode(Blend.Alpha) --Set blend to alpha so only letters will show context:DrawText("Rotation :".. self.ry .."",5,130) --Set text and position of text --context:DrawText("Speed :".. self.speed .."",5,140) --Set text and position of text end 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.