Advertisement

Need help with 2D oscillation

Started by March 25, 2014 10:49 PM
30 comments, last by Waylander 10 years, 10 months ago

Google for the definition of "perpendicular."


When you come up with something for the UnitDirectionVector above, calculate a unit vector perpendicular to it and use it where Alvaro has (perp.x,perp.y).

I'm not sure what your routine looks like at this point, but, at one time, you had the sprite moving in GetDirection(). Following that, for the sin() portion of the equation, you again had Normalize(GetDirection()) => traveling in a direction, and oscillating in the same direction. The vector which you multiply by the sin() should be perpendicular to the direction of travel.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Waterlimon, thank you for the definitions! Short and to the point. Your mention of dt is what I was thinking of when I was asking Buckeye earlier whether or not the time had to be calculated in some way before being used (and he said it didn't and that the gameTime could just be fed in there). I just didn't know what to call it. I'd seen it before, but just couldn't remember.

I'll see about implementing your version of this and see what I can come up with smile.png. As far as dt, I'm assuming that it is simply a case of storing a time variable and using subtraction to get what I need. I'm still getting a feel for how sprites move this way whereas before what I was doing was simply updating a vector by a certain amount every frame by adding or subtracting and not messing with anything like direction, velocity, etc.

Buckeye, I know what perpendicular is. What is throwing me off is when the terminology changes (telling me to use a direction, then telling me to use a speed, then telling me I need to use a direction again...things like that slow down my attempts at understanding what is going on). On the plus side, since I've had to (involuntarily) take a day or so away from this, I think I can look at it with a fresh set of eyes.

Up to this point, for whatever reason my sprite is being kept at the upper left-hand corner of the screen (0, 0) and isn't moving.

EDIT

I think I'm getting somewhere. My sprite is moving now but at a VERY slow rate. I'm not sure why and no matter what I try to adjust it doesn't get any faster. On the plus side it is going side to side a tiny bit (I changed my amplitude and frequency to 0.5 per Buckeye's suggestion) :). Any suggestions on a range of numbers to work with for this sort of thing?

Ulfhedhin

This topic is closed to new replies.

Advertisement