I'm making this gravity script but the objects just keep jumping higher and
higher all the time, and I cant find a solution to the problem.

Here is the script:
----------------------------------------------------------------------------
------------------
property spriteNum, x, y, Vx, Vy, Ax, Ay, dTime, gravity, dragC

on getPropertyDescriptionList me
  set pdlist to [:]
  addprop pdlist, #dTime, [#comment:"Speed or time increasement.",
#format:#float, #default:1]
  addprop pdlist, #Vx, [#comment:"Initial horizontal speed...",
#format:#float, #default:0]
  addprop pdlist, #Vy, [#comment:"Initial vertical speed...",
#format:#float, #default:0]
  addprop pdlist, #gravity, [#comment:"Gravity", #format:#float, #default:1]
  addprop pdlist, #dragC, [#comment:"Air resistance", #format:#float,
#default:0]
  return pdlist
end getPropertyDescriptionList

on beginSprite me
  set x = float(the locH of sprite spriteNum)
  set y = float(the locV of sprite spriteNum)
end

on exitFrame me
  if the locV of sprite me.spriteNum  > 230 then set Vy = -Vy
  if the locV of sprite me.spriteNum < 0 then set Vy = -Vy
  if the locH of sprite me.spriteNum > 310 then set Vx = -Vx
  if the locH of sprite me.spriteNum < 0 then set Vx = -Vx

  -- find the new values for
  set Ax = -dragC * Vx
  set Ay = gravity - dragC * Vy

  -- find the changes in velocity
  set dVx = Ax * dTime
  set dVy = Ay * dTime


  -- find the changes in position
  set dx = Vx * dTime
  set dy = Vy * dTime

  -- set the new velocities and position
  set Vx = Vx + dVx
  set Vy = Vy + dVy
  set x = x + dx
  set y = y + dy


  -- and now move the sprite to the
  -- calculated x and y position
  set the loc of sprite spriteNum = point(x,y)

end
----------------------------------------------------------------------------
-------------

Please help me...
Johannes Hansen


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to