Jump to content

How to reduce entity speed (force)?


Tomas
 Share

Recommended Posts

Hi, my entity has a mass of 10 and im trying to move it slow. I use (...if window:KeyDown(Key.W) then self.entity:AddForce(0,0,10,false) end) but entity moves too fast. Reducing force less than 10 will make entity immovable. How i can reduce the speed of entity?

Link to comment
Share on other sites

This is my code. Entity is not moving at all even with friction 0. Entity has collision box and shape box.

Script.camPos=Vec3()
Script.entPos=Vec3()
Script.camRotation=Vec3()
Script.mouseSensitivity = 15
Script.mouseDifference=Vec2()
Script.mouseOld=Vec2()
Script.currentMousePos=Vec2()
Script.mousepos=Vec2(0,0)
function Script:Start()
local window = Window:GetCurrent()
local context = Context:GetCurrent()

self.camera = Camera:Create()
self:UpdateCamera()
self.entity:SetFriction(1,1)
end
function Script:UpdateCamera()
local context = Context:GetCurrent()
local window = Window:GetCurrent()
self.currentMousePos = window:GetMousePosition()
window:SetMousePosition(Math:Round(context:GetWidth()/2), Math:Round(context:GetHeight()/2))
self.currentMousePos.x = Math:Round(self.currentMousePos.x)
self.currentMousePos.y = Math:Round(self.currentMousePos.y)
self.mouseDifference.x = Math:Curve(self.currentMousePos.x - Math:Round(context:GetWidth()/2),self.mouseDifference.x,3)
self.mouseDifference.y = Math:Curve(self.currentMousePos.y - Math:Round(context:GetHeight()/2),self.mouseDifference.y,3)
self.camRotation.x = Math:Clamp(self.camRotation.x + self.mouseDifference.y / self.mouseSensitivity,-90,90)
self.camRotation.y = self.camRotation.y + (self.mouseDifference.x / self.mouseSensitivity)

self.camera:SetRotation(self.camRotation)
self.entPos=self.entity:GetPosition()
self.camera:SetPosition(self.entPos.x,self.entPos.y+1.8,self.entPos.z)
self.entity:SetRotation(0,self.camRotation.y,0)


end

function Script:UpdateWorld()
self:UpdateCamera()
end
function Script:UpdatePhysics()
--Get the game window
local window = Window:GetCurrent()
self.entity:SetFriction(1,1)
if window:KeyDown(Key.W) then self.entity:SetVelocity(0,0,10,false) end
--if window:KeyDown(Key.W) then self.entity:AddForce(0,0,10,false) end
--if window:KeyDown(Key.A) then self.entity:AddForce(-speed,0,0,false) end
--if window:KeyDown(Key.D) then self.entity:AddForce(speed,0,0,false) end
--if window:KeyDown(Key.S) then self.entity:AddForce(0,0,-speed,false) end
end

Link to comment
Share on other sites

Don't know. Your code worked fine for me. Setting the friction to 0 just made the box slide for a little after the user input was no more. I can set the velocity.z down to 1 and it still moves. Also, using the AddForce.z at 10 works as well when the friction is set to 0. If the friction is set to 1 then just increase the value to overcome the box's mass and gravity. Speaking of which, if the numbers above are not working for you what is your scene's gravity set to? The default is 25.

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

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.

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.

 Share

×
×
  • Create New...