Discord
Login
Community
DARK THEME

How do I make objects fall

I'm writing a program and I need objects to fall if the player doesn't hold them with the mouse, how do I make that with microScript. I tried decreasing the y coordinates, but the objects just teleport to y = 0.

ALSO, another question, then I click the mouse the object teleport to my cursor, I DONT WANT THAT. I need to object to change its coordinates to the coordinates of the cursor ONLY then the cursor is touching the mouse. I will have multiple objects and I can't have all of them just teleporting to the same place at once

If you want to hold an object, do this

if mouse.x > [object]x-16 then

if mouse.x < [object]x+16 then

if mouse.y > [object]y-16 then

if mouse.y < [object]y+16 then

if mouse.left then

[insert desired function]

end

end

end

end

end

As for making the object fall, can you copy+paste the line of code that won't work?

update = function()

if mouse.pressed then

  rect.x = mouse.x

  rect.y = mouse.y

else if mouse.release then

  while rect.y >= 0

    rect.y = rect.y -= 1

  end

end 

end

end

(This is the program I used to make the rectangle fall, I want the object to stop falling at the y = 0 coordinate (since there would be a table), but I still can't figure out how to make the object FALL and not TELEPORT)

Try decreasing the amount that you're subtracting from the y coordinate

Nothing has changed unfortunately :(

Hmm, perhaps we could say that if the mouse coordinates match those of the object, its speed immediately becomes zero, and otherwise, it continues its fall.

when using "while" it wont continue with the program until it is not true. it's good for loops that change constantly but in this scenario it just keeps looping until it hits zero. use and "if" instead and it should work

if mouse.pressed then
    rect.x = mouse.x
    rect.y = mouse.y
  else if rect.y > 0 then
    rect.y = rect.y -= 1
  end

you guys where checking if mouse.release thats only if it was just released after being clicked not when it wasn't clicked

OH MY GOD THANK YOU SO MUCH, IT WORKED!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community