Sign in to follow this  

Steering Behavior Seeking code malfunction

Recommended Posts

I got some code that im tweaking. Ive almost got it to work. It doesn't seem to work right though. First when it first starts in my INIT function that I set to target 50,0,0, it jets off way to fast. Here is what im doing.


seek(IvVector3 target)

    IvVector3 desired = target - position;
    desired = desired * maxspeed;
    IvVector3 steer = desired - velocity;

    if(steer.LengthSquared() > maxforce * maxforce)
        steer *= maxforce;



   void applyForce(IvVector3 Force)

    acceleration = Force;


In my update Function


velocity += acceleration;


position += (velocity * mTimer.DeltaTime());
TESTS = XMMatrixTranslation(position.x,0,position.z);
// Reset acceleration to 0 each cycle

Also when it reaches the target, it completey stops instead of going back and forth



Share this post

Link to post
Share on other sites

This might not be precisely the problem, but it looks you're basing your homing/seeking on the current velocity of the object.  I think what you're really aiming to do (pun intended) is to separate the object's velocity vector from its heading.  In other words, I think your update should:

  • Look at the direction the object "wants" to go -- this is the desired direction you've calculated (it should be a normalized vector)
  • Look at the object's (missile or something?) current heading -- which direction is it presently facing?  (should also be a normalized vector)
  • Determine the angle between the two vectors; i.e., determine how to rotate the object to match the missile's heading to the desired vector (you'll probably need an angle and axis, as an angle of rotation is meaningless, if not also given an axis to rotate around)
  • Determine force/impulse to apply to the missile, to accomplish the desired rotation of its heading

Note:  The missile should always be thrusting -- traveling "forward" along its heading vector.  The goal of this algorithm is to determine how to change that heading.  Of course, in every frame, because the missile is moving, the "desired" vector will change, which will cause the rotational force/impulse to change, which will cause the missile's heading to change.  You'll probably be able (read: "need") to tweak a few parameters to get the seeking to behave the way you want.

A caveat: I've never written a homing/seeking missile before, so I could be somewhat off - but at a high level, I think your steps should look something like what I've described.

Another caveat: I gave my answer assuming you want to avoid the "dreaded quaternion".  Quats would probably make easy work of this problem, but I'm not sure what your comfort level is with that.

Have any experts in the community done something like this?


Share this post

Link to post
Share on other sites

You're not multiplying your acceleration value by dt.


Also, you may want to change applyForce to use += instead of = since you're probably going to want to apply more than one force at a time.


Are you reading Millington?

Edited by Khatharr

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By noodleBowl
      I was wondering if someone could explain this to me
      I'm working on using the windows WIC apis to load in textures for DirectX 11. I see that sometimes the WIC Pixel Formats do not directly match a DXGI Format that is used in DirectX. I see that in cases like this the original WIC Pixel Format is converted into a WIC Pixel Format that does directly match a DXGI Format. And doing this conversion is easy, but I do not understand the reason behind 2 of the WIC Pixel Formats that are converted based on Microsoft's guide
      I was wondering if someone could tell me why Microsoft's guide on this topic says that GUID_WICPixelFormat40bppCMYKAlpha should be converted into GUID_WICPixelFormat64bppRGBA and why GUID_WICPixelFormat80bppCMYKAlpha should be converted into GUID_WICPixelFormat64bppRGBA
      In one case I would think that: 
      GUID_WICPixelFormat40bppCMYKAlpha would convert to GUID_WICPixelFormat32bppRGBA and that GUID_WICPixelFormat80bppCMYKAlpha would convert to GUID_WICPixelFormat64bppRGBA, because the black channel (k) values would get readded / "swallowed" into into the CMY channels
      In the second case I would think that:
      GUID_WICPixelFormat40bppCMYKAlpha would convert to GUID_WICPixelFormat64bppRGBA and that GUID_WICPixelFormat80bppCMYKAlpha would convert to GUID_WICPixelFormat128bppRGBA, because the black channel (k) bits would get redistributed amongst the remaining 4 channels (CYMA) and those "new bits" added to those channels would fit in the GUID_WICPixelFormat64bppRGBA and GUID_WICPixelFormat128bppRGBA formats. But also seeing as there is no GUID_WICPixelFormat128bppRGBA format this case is kind of null and void
      I basically do not understand why Microsoft says GUID_WICPixelFormat40bppCMYKAlpha and GUID_WICPixelFormat80bppCMYKAlpha should convert to GUID_WICPixelFormat64bppRGBA in the end
    • By HD86
      As far as I know, the size of XMMATRIX must be 64 bytes, which is way too big to be returned by a function. However, DirectXMath functions do return this struct. I suppose this has something to do with the SIMD optimization. Should I return this huge struct from my own functions or should I pass it by a reference or pointer?
      This question will look silly to you if you know how SIMD works, but I don't.
    • By pristondev
      Hey, Im using directx allocate hierarchy from dx9 to use a skinned mesh system.
      one mesh will be only the skeleton with all animations others meshes will be armor, head etc, already skinned with skeleton above. No animation, idle position with skin, thats all I want to use the animation from skeleton to other meshes, so this way I can customize character with different head, armor etc. What I was thinking its copy bone matrices from skeleton mesh to others meshes, but Im a bit confused yet what way I can do this.
    • By mister345
      Does buffer number matter in ID3D11DeviceContext::PSSetConstantBuffers()? I added 5 or six constant buffers to my framework, and later realized I had set the buffer number parameter to either 0 or 1 in all of them - but they still all worked! Curious why that is, and should they be set up to correspond to the number of constant buffers?
      Similarly, inside the buffer structs used to pass info into the hlsl shader, I added padding inside the c++ struct to make a struct containing a float3 be 16 bytes, but in the declaration of the same struct inside the hlsl shader file, it was missing the padding value - and it still worked! Do they need to be consistent or not? Thanks.
          struct CameraBufferType
              XMFLOAT3 cameraPosition;
              float padding;
    • By esenthel
      Just finished making latest WebGL demo for my game engine:
      Let me know what you think,
      as of now only Chrome and Firefox can run it.
      Edge, Safari, Opera have some unresolved bugs at the moment.
  • Popular Now