Possible? Stop Physic Force applied

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Possible? Stop Physic Force applied

Post by weilies »

i have applied the following code

Code: Select all

ball.b:applyForce(5000, -1000)
the ball move right top, my question is
is it possible to stop the ball from moving? or How to stop for 5 seconds
Then continue the force again

Thanks for the guide
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Possible? Stop Physic Force applied

Post by Robin »

Well, I think you could make a MouseJoint to it and remove it after a certain amount of time? (But that means that other forces will be counteracted as well, I don't know if that is what you want.)
Help us help you: attach a .love.
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Re: Possible? Stop Physic Force applied

Post by weilies »

hi Robin,

Not kinda understand your suggestion.
Can you run my attached lua?

Once you run it, press "b" and it will move to top right
I believe you can visualize after you run my script
The keypoint is to "stop" after the "applyForce" applied
Attachments
main.lua
(1.97 KiB) Downloaded 245 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Possible? Stop Physic Force applied

Post by Robin »

See http://love2d.org/wiki/love.physics.newMouseJoint
You can just :destroy() the joint when you want to set the ball loose.

If you only want the force to be applied after, say, 5 seconds but have gravity and so still act on the ball in the mean time, you could do something like:

Code: Select all

timer = nil
function love.keypressed(key) -- I wouldn't apply force while holding a key
    if key == 'b' then
        timer = 5
    end
end

function love.update(dt)
    world:update(dt)

    if timer then
        timer = timer - dt
        if timer <= 0 then
            timer = nil
            ball.b:applyForce(300, -320)
        end
    end
end
Help us help you: attach a .love.
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Re: Possible? Stop Physic Force applied

Post by weilies »

Destroy method seems like "destroy" my window, my whole app crashed

code

Code: Select all

function love.update(dt)
    	    world:update(dt)
	
  if love.keyboard.isDown("p") then --press the left arrow key to push the ball to the left
    ball.b:applyForce(horiForce, vertForce * -1)	
	text = 'press b'.."\n" .. text
  end
  
  if love.keyboard.isDown("o") then --press the left arrow key to push the ball to the left
    ball.b:destroy()
  end
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Re: Possible? Stop Physic Force applied

Post by weilies »

i figure out a way

which is NOT to trigger following function "world:update(dt)"

Code: Select all

-- callback every frame
function love.update(dt)
    
	if haltPhysic ~= 1 then
		world:update(dt)
	end
it's JUST THAT SIMPLE!!!

and still we can apply
ball.b:applyForce(20000, 2000 * -1)
behind the scene

and afterthe animation end, we can unfreeze "world:update(dt)" function
with new force apply
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Possible? Stop Physic Force applied

Post by Robin »

weilies wrote:Destroy method seems like "destroy" my window, my whole app crashed
No, I didn't mean that. What I meant was:
  1. Create a MouseJoint
  2. When you want the body to move, destroy the MouseJoint. (NOT the body.)
weilies wrote:i figure out a way

which is NOT to trigger following function "world:update(dt)"
Oh, but that stops all physics. I thought you didn't want that.

Seriously though, if what you want to do is so simple, it might be easier not to use love.physics. (Seeing as you don't seem to need any complex collision testing or anything.)
Help us help you: attach a .love.
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Re: Possible? Stop Physic Force applied

Post by weilies »

Yes, but no, I prefer to use Wht the framework provided rather to dirty my hand on my own throw ball logic

My gameplay is based on angle and force user selected, throw a ball and see how far it can goes
And if my ball hit ground and a superpower item on the ground, mean my ball touch the superpower object(collide) I will need to play an animation and change the force

I am definitely not going to code it :)
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 2 guests