Moving sprite relative to another sprite

This is a discussion on Moving sprite relative to another sprite within the Game Programming forums, part of the General Programming Boards category; Hello. I know the "roterating ship" kinda uses about the same algorithm, but there were some factors there I didn't ...

  1. #1
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717

    Moving sprite relative to another sprite

    Hello.

    I know the "roterating ship" kinda uses about the same algorithm, but there were some factors there I didn't understand.
    Also, sorry if the title is bad...

    Well, I have one character class that has a vector of it's position.
    This character has a function that moves it towards a position pointer, and I want the fastest and still nice looking algorithm for for this to happen.
    What I mean is that the position pointer might change, thus the character needs to change where to move... I do have an algorithm myself, that I understand, but I believe it would be too slow, as the code runs a million times in the minute, and this algorithm makes a new direction each time... (I did describe it in the rotating ship thread)

    So has anyone got any advice?

    Code:
    hgeVector m_hVec_position;
    
    void MoveRelative(const hgeVector &position_, const float speed_){
    
    	hgeVector* p_position = &position_;
    
    }
    that's what I've got so far :S
    hope I was clear...

    Thanks in advance!
    Currently research OpenGL

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    So you have an object at point A, and want to move it towards a moving object at point B i take it?

    Construct a normalized vector betwean the 2 and have that be your directional vector and move object at point A along that vector. This vector only needs to be recalculated when object at point B moves. After that just add some fluff-fluff (you could make it so the A object only can turn a certain amount per second, and if you keep a constant speed forward you would have to recalculate it every time A or B moves but would give nicer curve movement if the delta change in B is large).

  3. #3
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    I know this method, still when B moves, it would be calculated a million times, since B can move for more than a minute, infact it can move for an hour and so on...
    I thing the overhead would be a killer with this method...
    Currently research OpenGL

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    I cant think of a way to not having to recalculate it, if B moves around randomly you would have to recalculate your direction as soon as B moves. And its not that many calculations, you still only run them once every frame so maybe 60 times/second? Thats not overly bad.

  5. #5
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    well, I see the calculations as graphics in my head automaticly xD if each calculated direction would be drawn in white, the whole screen would go white,, if the object went all the way around the screen...
    But I also noticed, I don't need this :S
    But thanks anyways!
    Currently research OpenGL

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Calculating per frame should not be an issue. The only other way to do this is to calculate the vector once and then alter it relative to the base line vector you calculated. So subtract the current vector to the target from the known calculated vector and use the offset to change the pre-computed target vector.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Object not moving to angle
    By mike_g in forum C Programming
    Replies: 1
    Last Post: 06-22-2007, 09:30 AM
  2. DirectX 9 sprite issue
    By maxthecat in forum Game Programming
    Replies: 9
    Last Post: 05-18-2006, 04:04 AM
  3. GDI sprite (Win32 API)
    By fiff in forum Game Programming
    Replies: 4
    Last Post: 06-24-2005, 09:09 AM
  4. Replies: 3
    Last Post: 05-12-2003, 05:49 PM
  5. problem in allegro with sprite leaving trail
    By Leeman_s in forum C++ Programming
    Replies: 18
    Last Post: 09-13-2002, 03:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21