Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Steering Behavior Seeking code malfunction

$
0
0
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.Normalize(); desired = desired * maxspeed; IvVector3 steer = desired - velocity; if(steer.LengthSquared() > maxforce * maxforce) { steer.Normalize(); steer *= maxforce; } applyForce(steer); } void applyForce(IvVector3 Force) { acceleration = Force; } In my update Function velocity += acceleration; if(GetKeyState(0x31)) { seek(IvVector3(0,0,50)); } if(GetKeyState(0x32)) { seek(IvVector3(-50,0,0)); } position += (velocity * mTimer.DeltaTime()); TESTS = XMMatrixTranslation(position.x,0,position.z); // Reset acceleration to 0 each cycle acceleration.IsZero(); Also when it reaches the target, it completey stops instead of going back and forth

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>