QuantumPixel Posted December 18, 2016 Posted December 18, 2016 Hello. I am super new to Leadwerks, Lua script, and OOP languages in general. I am just trying to put together a simple game where the player can move a character around a room and dodge a bouncing ball-of-death; but the collisions are giving me a hard time. At this point, the script attached to my player character model simply contains the following code: Script.moveRate = 0.05 --float "Movement Rate" function Script:UpdatePhysics() if window:KeyDown(Key.W) then self.entity:Translate(0, 0, self.moveRate) end if window:KeyDown(Key.S) then self.entity:Translate(0, 0, -self.moveRate) end if window:KeyDown(Key.A) then self.entity:Translate(-self.moveRate, 0, 0) end if window:KeyDown(Key.D) then self.entity:Translate(self.moveRate, 0, 0) end end I have tried using Leadwerk's built-in physics to handle collisions, but they yield unwanted results. If the Physics Mode is set to Rigid Body, then the character model gets knocked over upon making contact with a wall brush; and if the Physics mode is set to Character Physics, the model sinks halfway into the floor brush and bounces when it collides with a wall, sometimes being launched away from the wall when the button is released. I have tried various setting combinations of Physics Mode and Physics Types, but none have yielded better results. In light of this, I thought I might try writing my own code to handle the collision behavior, but I can't seem to find any commands in the API reference that deal with collisions, aside from the CollisionHook command, which I am completely baffled by. (I have no idea what a "hook" is, and there is no example code given.) Apparently, I am missing something, somewhere. Can anyone point me in the right direction? Thanks! Quote
Thirsty Panther Posted December 18, 2016 Posted December 18, 2016 Check out the Marble Tutorial. In the coin part it shows how to detect collision between the marble and the coin. Using function Script:Collision(entity, position, normal, speed) Quote
Genebris Posted December 18, 2016 Posted December 18, 2016 entity:Translate isn't supposed to work with physical objects, it will brake the simulation. You should use AddForce or PhysicsSetPosition. Use methods from Physics part http://www.leadwerks.com/werkspace/page/api-reference/_/entity/ Quote
Josh Posted December 18, 2016 Posted December 18, 2016 When you use the entity movement commands like Translate, it does not result in actual physics forces being applied. What you really want to do is call AddForce() or even SetVelocity() instead. Make sure the object has a mass greater than zero. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
QuantumPixel Posted December 19, 2016 Author Posted December 19, 2016 I thank you for your reply, Genebris and Josh. It helped. Quote
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.