Moving a sprite along a vector (line)

Hello all,
I am trying to get a simple image to follow the mouse cursor, to let the player control a ship in a shooting game.
The problem is that I don't want the ship to follow exactly on top of the cursor (like a .moveTo method would do), but rather have it so the ship sort of lags behind the cursor, limiting the maximum speed it can travel.
I know how to get the position of the ship, and the position of the cursor, but I don't know how to get the ship to move along the vector created by the two points.
Please help!

Arik is mostly right
calcAngle should NOT be returning in angles, so that is my fault. however, this would not have been preventing movement, it would simply make it stutter around a bit (but going the right direction)
now, here is why your sprites are not moving..
your sprite's X/Y coordinates are likely stored as ints, but since the velocity is so low, the x-offset (how much the x is going to move) may be something like 0.1432.
so then when you apply that to x, you find the problem:
x+=0.1432
let's say x is 4.
4+=0.1432 = 4.1432
since your x is an int, this is changed to 4. thus, no change! (and no motion)
so you have two options..
1. change velocity to a higher value (though this will not be able to stop pinpoint on the mouse location, since it will eventually be like a 0.02 offset)
2. do all variables with floats or doubles
I suggest option number 2. when it comes to angles, you do need precision.
I have uploaded an example for you to try out:
http://woogley.net/misc/MouseFollow/MouseFollow.jar
just move the mouse around and watch as the ball follows your mouse around. this example is using a velocity of 1.0.
go ahead and play with the source code, change the velocity, etc:
http://woogley.net/misc/MouseFollow/MouseFollow.java

Similar Messages

  • Is there any way of exporting a clip (example 1 hour) into 4 seperate 15 min clips at the same time? Or does anyone have any ideas along the same lines to save time? Add my skype baconhousevidz if you can help or are unsure of what im asking

    Is there any way of exporting a clip (example 1 hour) into 4 seperate 15 min clips at the same time? Or does anyone have any ideas along the same lines to save time? Add my skype baconhousevidz if you can help or are unsure of what im asking
    thanks everyone

    BaconHouseVidz wrote:
    … at the same time…
    in hope to speed things up?
    no, no effect.

  • WH  tax line items cleared along with Other line items Message no:8I701

    hI guru,
    When i run J1INCHLN  System givem the error is : Withholding tax line items cleared along with other line items, message no:8I701
    Pleas any one give solution ..
    I also cheked as respective g/l for tds IN FBL3N . All line items are opend.
    Also cheked all selection parameter in J1INCHLN  and FBL3N .is same .
    Why the sys behaviour like this .
    Thanks is andvance
    Milind

    HI,
    he error is occuring in this part of the
    unction Module J_1IEWT_CHALLAN_UPDATE
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    LOOP AT p_t_ausz1.
    Select the cleared line item from bseg table.
       SELECT SINGLE * FROM bseg INTO  p_bseg_tab
                WHERE bukrs = p_t_ausz1-bukrs
                AND   belnr = p_t_ausz1-belnr
                AND   gjahr = p_t_ausz1-gjahr
                AND   buzei = p_t_ausz1-buzei
                AND   ktosl = 'WIT'
                AND   qsskz NE space .
       IF sy-subrc <> 0.
    This is not an ewt clearing transaction relevant for challan update.
         p_no_with_clear = 'X'.
         EXIT.
       ELSE.
         APPEND p_bseg_tab.
       ENDIF.
    ENDLOOP.
    Even if one line item chosen is not of withholding tax entry, system
    should exit by error message.
    DESCRIBE TABLE p_bseg_tab LINES  p_bseg_lines.
    DESCRIBE TABLE p_t_ausz1  LINES  p_with_lines.
       IF p_bseg_lines > 0.
    At least one entry is found in bseg table for challan update.    IF p_with_lines NE p_bseg_lines.
    At least one line chosen by the user is not for challan updation.
          MESSAGE e701(8i).
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
    This is a clear case,that you are trying to post some documents
    which does not match with the selection parameters.
    I feel the above problem could be due to some document/s (open items of
    the earlier years)are incorrect which is causing the reported problem.
    Kindly run the challan update program for smaller date range so that you
    can find the faulty document.
    Hope this solves your query.
    Reg
    Madhu M

  • Withholding tax lines are being cleared along with other line items

    Hi All,
    While doing J1INCHLN(payment making of TDS), system giving error i.e.
    "Withholding tax lines are being aleared along with other line items"
    Please suggest me in this issue...it would be great help for me.
    Thanks,
    Saisri

    Hi,
    As per my analysis we found some documents, here We have made advance payment to vendors with TDS and again rised invoce to vendors with TDS and these documents have been nockedoff in F-54.
    We have many documents of such nature and as per me it is because of these documents  the system is throwing error. Pls. advice as to how to proceed on this.
    Thanks,
    Saisri

  • Why do vector lines appear different in my Photoshop document compared to the PDF that was created using "Scripts Layer Comps to PDF"? And how do I get them to look the same?

    Why do vector lines appear different in my Photoshop document compared to the PDF that was created using "Scripts > Layer Comps to PDF"? And how do I get them to look the same?

    BOILERPLATE TEXT:
    If you give complete and detailed information about your setup and the issue at hand, such as your platform (Mac or Win), exact versions of your OS, of Photoshop and of Bridge, machine specs, what troubleshooting steps you have taken so far, what error message(s) you receive, if having issues opening raw files also the exact camera make and model that generated them, etc., someone may be able to help you.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • How to get Header data into multiple times along with the Line Items

    Dear All,
      I have problem while mapping the Header data and line item data to the flat file structure, Header data have to repeat along with the Line item data in the flatfile.
    Details is below.
    Example
    Header record is one
    E1EDK01
    E1EDKA1
    Line items are two
    E1EDP01
    E1EDP01
    I want in the flat file two records having duplicate data in the fields which is belongs to header data
    Like :
    Record #  partner data     Line item data
    Record 1 : WE name1 city   00010 materialname1 156
    Record 2 : WE name1 city   00020 materialname2 198
    ( WE name1 city - data is same in the record 1)
    For this what I did is I mapped the node E1EDP01 to the flat file message type node then I got all the line item data and first record is with header data but not in the second record.
    I tried all node functions but no result because Idoc itself header data exists one record, I am not able to copy.
    If any one knows , please give solution.
    It is great help to me.
    Thanks in Advance.
    Ramarao

    Dear Ramarao,
    This will help you,
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/f59730fa-0901-0010-df97-c12f071f7d3b
    No Documentation for Mapping Function useOneAsMany (Mapping Problem)
    /people/claus.wallacher/blog/2006/04/17/replication-of-nodes-using-the-graphical-mapping-tool
    /people/narendra.jain/blog/2005/12/30/various-multi-mappings-and-optimizing-their-implementation-in-integration-processes-bpm-in-xi
    /people/sravya.talanki2/blog/2005/12/08/message-mapping-simplified-150-part-ii
    Thanks & Regards
    Agasthuri Doss

  • I just moved my safari off the bottom line of icons on my mac. where do I find now, or how do i get it back?

    i just moved my safari off the bottom line of icons on my mac. where do I find now, or how do i get it back?

    Simply go back into your applications folder and find the icon for Safari. Click and drag the icon back into the menu bar. You can choose where to place it by moving it to the perfered place in the menu bar and unclick to set.

  • Please help me in Moving/ Walking sprites in Microsoft visual studio 2010?

    Please help me in Moving/ Walking sprites in Microsoft visual studio 2010?  or can anyone give me a sample of your game code for moving sprites thanks.

    Hi Sandwhale13,
    Do you mean that you want to develop an Game? If so, is it related to the XNA Game development?
    If so, this forum would be better for this issue:
    http://xboxforums.create.msdn.com/forums/
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can I create additional "Sent Mail" folders so that I can organize my sent mail along the same lines as the inbox? I use Mail v 4.5

    How can I create additional or sub "Sent Mail" folders so that I can organize my sent mail along the same lines as the inbox? I use Mail v 4.5.

    Thank you for your reply Don, but I had already gone through that procedure and it will only create new mailboxes for received mail. I want to create new mailboxes for sent mail, i.e. the first column being "to" not "from". Under the Mailbox menus there is an option "Use This Mailbox For" but all the options under that (including Sent) are greyed out. Unfortunately the View/Columns option to change from "From" to "To" changes all mailboxes not just the active one.

  • How can I create a vector line

    A vector image editor needs edit a vector line.
    How can I create it ? thanks

    a biot more information would'n hurt anyone ;-)
    What do you want to know:
    How to calculate the new line-position / attributes after a mouse-drag?
    How to use mathematical 'vectors'?
    How to paint it?
    Eth

  • Image to vector lines

    how can i convert an image(Jpeg or pdf) into vector lines in illustrator and export as dxf file?

    Barbara,
    If you wish to make it clean and simple, recreating with the Pen Tool and probably suitable tools in the Rectangle Tool Group (and maybe others) on top of the locked image is the first option to consider.

  • How do I 1)use airbrush type tool in illustrator CS4 or 2) use PS4 airbrush tool on vector line art?

    That's basically my question in a nutty nut.  I am drawing illustrations in Illustrator,
    can't find an airbrush tool there, so I export to Photoshop to use that airbrush and the
    lines pixelate.  I want the clean, vector lines of Illustrator with the yummy fuzzy airbrush tool.  In short, can I go back and forth from Illustrator to Photoshop without the line art ping ponging between pixel and vector?

    See this PDF for one approach. The subject was really more about exploring ways to exploit Isolation Mode, but it does so in the context of a poor-man's "airbrush" effect.
    I want the clean, vector lines of Illustrator with the yummy fuzzy airbrush tool.
    In reality, then, you're not wanting vector artwork to look like vector artwork. Here's the thing:
    Vector artwork, is by its fundamental nature "hard edged." That's one of its advantages and one of its disadvantages. Soft-edged fuzzy effect (and its sister, texture) is one of the mainstays of raster imaging. It's one of the main reasons why there are two primary kinds of computer graphics.
    Historically, soft edges and graduations are primarily done with Blends and Graduated Fills. A Blend is really just a semi-automated stack of multiple paths with incrementally changing color. Grad fills are mathematically-defined variations of a path's fill color across the path. Generally speaking, grad fills are limited to a small set of geometric shapes. For most of Illustrator's history that was a very limited set: linear or radial. So when you needed to render tonal graduations in more elaborate shapes, you employed Blends.
    More recently, programs have acquired a newer construct, which is an elaboration of grad fills: Mesh Grads. Mesh Grads are also mathematically-derived and remain as such up to print time--that is, they are vector. They offer more control over the shape of the color transitions. But that control is quite tedious, and is not at all like painting with an airbrush.
    That's about the extent of it when it comes to maintaining "clean, vector edges". With skill and discernment, the results can look just as realistic as airbrush work, and it can be entirely vector. But the interface for doing it is not an emulation of painitng with an airbrush.
    Far more common than a purely vector tool in a vector drawing program that tries to act like an airbrush is the workaround of applying filters or effects to vector paths. Doing that is not purely vector: It's actually rasterization that is re-applied whenever you edit the paths. If you set such an effect as the current default, then you can draw paths with the Brush tool, the Pencil Tool, or really, any of the vector path tools, and that's about as close to emulating an airbrush in a vector program as you'll get. The PDF mentioned above employs that kind of approach. But you should understand, you're really creating raster images when you do that. It's just that, rather than the raster images being "nailed down", they are effectively deleted and re-created on-the-fly if you edit the paths to which the effect is applied.
    Illustrator isn't great at this. Other programs--Xara Xtreme in particular--do it much faster and responsively. But again, even though it retains the lossless editability advantage of vector art, the soft-edged effects are not really vector art. The are on-the-fly rasterizations of vector art.
    Look up Blends, Grads, and Mesh Grad in Illustrator's Help files.
    JET

  • Can a behavior affect the individual points of a vector line?

    Hi All,
    I've drawn a vector line in Motion using the pen tool, and would love to apply a random motion or wiggle so that the points of the line themselves would shake, as opposed to the entire line shaking as one solid object. Is this possible? I've been unable to fine a way to achieve this. Thanks in advance.

    Apologies Cory, I can see how to make the Wriggle Behaviour apply to individual points of Shapes, but not Paint Strokes. If you take a look at Wiggle Star in the content folder, check out the Behaviour. There's an Apply to Points setting. IF your Paint Stroke could be a Shape instead, you can choose Outline and an offset to make it look like a line instead of a closed shape. If your Paint Stroke is not too jagged or complicated, that is. Otherwise, I'd go for the Record method. Hopefully someone who knows better will chime in with a better solution for you.

  • Vector lines and control points stay onscreen

    Photoshop CS6 64bit WIndows 7 64 Bit.
    Using pen tool to create a mask.
    After de-selection of path (using pointer tool, paintbrush or anything else) the vector line including the control points does not disappear as normal.
    Deleting the layer removes it, but changing the visibility of the layer does not have any effect - it simply stays onscreen.
    Radeon HD4850 card with latest drivers.

    Photoshop CS6 64bit WIndows 7 64 Bit.
    Using pen tool to create a mask.
    After de-selection of path (using pointer tool, paintbrush or anything else) the vector line including the control points does not disappear as normal.
    Deleting the layer removes it, but changing the visibility of the layer does not have any effect - it simply stays onscreen.
    Radeon HD4850 card with latest drivers.

  • Moving an image along a line

    hi,
    for a part of a project i need to move an image
    (of a robot) across a path.
    the path is a vector containing line (with a start and ending point).
    i know how to show the image in a point. but
    i need the code to move it along the line

    Look at the Line2D class, it my help.
    Also read this link
    http://forum.java.sun.com/thread.jsp?forum=20&thread=28813

Maybe you are looking for