RastiLechner Posted March 18, 2015 Share Posted March 18, 2015 i have created a ball in editor i gave him physics mass and sphere collision. in next ste i write for him script . but the script don't work. can somebody explain me whats the problem ? script: if KeyHit(Key.W) then Entity AddForce(0,0,100,true) attached file is screenshot thanks p.s. sorry for my english Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 18, 2015 Share Posted March 18, 2015 no screenshot attached... but just a simple example: - Create the sphere and give it this for physics properties - Create a script and add the following code to it Script.camera = "" --entity "Camera" function Script:UpdateWorld() local window = Window:GetCurrent() if window:KeyDown(Key.W) then self.entity:AddForce(0,0,10,true) end if window:KeyDown(Key.S) then self.entity:AddForce(0,0,-10,true) end if window:KeyDown(Key.A) then self.entity:AddForce(-10,0,0,true) end if window:KeyDown(Key.D) then self.entity:AddForce(10,0,0,true) end self.camera:SetPosition(self.entity:GetPosition(true) + Vec3(0,1,-2)) end -Attach the script to the sphere -Drag the scene's camera into the sphere's script 'camera' textbox as shown in image above 4 Quote 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 More sharing options...
RastiLechner Posted March 19, 2015 Author Share Posted March 19, 2015 Thank you so much.. this was very helpfull for me Script.camera = "" --entity "Camera" function Script:UpdateWorld() local window = Window:GetCurrent() if window:KeyDown(Key.W) then self.entity:AddForce(0,0,10,true) end if window:KeyDown(Key.S) then self.entity:AddForce(0,0,-10,true) end if window:KeyDown(Key.A) then self.entity:AddForce(-10,0,0,true) end if window:KeyDown(Key.D) then self.entity:AddForce(10,0,0,true) end if window:KeyHit(Key.Space) then self.entity:AddForce(0,500,0,true) end self.camera:SetPosition(self.entity:GetPosition(true) + Vec3(0,2,-4)) end ok thats cool but he jump in the air too gives something like if self.entity collision(world) then jump=true :end if window:KeyHit(Key.Space) and jump=true then self.entity:AddForce(0,500,0,true) end thanks Quote Link to comment Share on other sites More sharing options...
CoolBeans Posted March 27, 2015 Share Posted March 27, 2015 Got this to work cool. One problem you can keep jumping the ball even in the air. I presume this line of code prevents that. if self.entity collision(world) then jump=true :end Of course its not right Ive fiddled around how to properly add it in? Script.camera = "" --entity "Camera" function Script:UpdateWorld() local window = Window:GetCurrent() if window:KeyDown(Key.W) then self.entity:AddForce(0,0,10,true) end if window:KeyDown(Key.S) then self.entity:AddForce(0,0,-10,true) end if window:KeyDown(Key.A) then self.entity:AddForce(-10,0,0,true) end if window:KeyDown(Key.D) then self.entity:AddForce(10,0,0,true) end if window:KeyHit(Key.Space) then self.entity:AddForce(0,500,0,true) end self.camera:SetPosition(self.entity:GetPosition(true) + Vec3(0,1,-5)) end Thanks. CB Quote Link to comment Share on other sites More sharing options...
CoolBeans Posted March 29, 2015 Share Posted March 29, 2015 Can anyone help with the above question? Also I have a rotating block to navigate my ball around. If my ball is already rolling everything reacts right. I hit the rotating block and it forces me to move etc but... If my ball is standing still/idle the rotating box goes right thru my ball as if its not there. Ive messed with settings and mass and what not and can't find a working combo. Lastly do I really need to make a sphere in 3dsmax and import into Leadwerks because I can NOT get a perfectly round ball no matter what I try in Leadwerks am I missing something so simple? How do you scale object on all xyz at the same time? In 3dmax you grab where the x.y.z meet. I I hope someone can comment so I can progress soon. Edit I have the same ball settings as illustrated above. Must be the box setting. There is no collision if the ball is NOT in motion, odd. Off to tinker some more. Edit Tried all settings/combinations arrrrrrr! 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.