Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Make rendered image move thru specified direction

Hi guys, I want to learn how I can render a rectangle/some image to a given point, but I want it to keep moving through the point, but maintain the same direction. I wanna make an object move (gun bullet) thru the CurrentTouch coordinates. How can I do this? Thanks. I know how to make an object move TO the tap position, but I wanna make the bullet keep the same direction of the tap and keep going, could I see an example of this if possible? That'd be great! Merry Christmas to you all. :)

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 7,468

    If you can move the object to the point, you should be able to make it keep going. Just take the x,y difference of the current point and the TO point, divide that by how fast you want it to move, and keep adding that calculated x,y value to your object.

  • dave1707dave1707 Mod
    Posts: 7,468

    If you want your object to move at the same speed irregardless of the different starting distances, use the vector normalize function.

  • dave1707dave1707 Mod
    Posts: 7,468

    @Coder1500 Here's an example. Tap the screen where you want to object to pass thru. You can tap the screen at any time. Changing the speed value will change the speed the object moves.

    displayMode(FULLSCREEN)
    
    function setup()
        orig=vec2(WIDTH/2,HEIGHT/2)
        diff=vec2(0,0)
        to=vec2(0,0)
        speed=3
    end
    
    function draw()
        background(0)
        fill(255)
        orig=orig-diff*speed
        ellipse(orig.x,orig.y,5)
        ellipse(to.x,to.y,5)
    end
    
    function touched(t)
        if t.state==BEGAN then
            to=vec2(t.x,t.y)
            diff=(orig-to):normalize()
        end
    end
    
  • Thanks Dave!

Sign In or Register to comment.