Jump to content
QuantumPixel

Need Help With Basic Collisions

Recommended Posts

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!

Share this post


Link to post

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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...