2

I want to have a particle field in Yampa. The single particle should just move in a straight line, but depending on an angle given. That angle and movement speed changes depending on the player's speed and angle. I don't know how better to explain, I'm developing something similar to this game.

Anyway, my code for now looks like this:

star :: (Float, Float) -> SF (Float, Float) (Float, Float)
star p0 = proc (vel, a) -> do
    rec
        v <- integral -< vel *^ (cos a, sin a)
        p <- clampS ^<< (p0 ^+^) ^<< integral -< v ^+^ p
    returnA -< p

clampS s@(x, y) | x > 1 = (x-2, y)
                | x < (-1) = (x+2, y)
                | y > 1 = (x, y-2)
                | y < (-1) = (x, y+2)
                | otherwise = s

vel is the current speed, a is the current angle. But the particles move in, well, strange ways. (Full code here

Unfortunately, I am sure I am thinking in a wrong way, but I have not yet been able to figure out how to do that, especially how using integral correctly.

Maybe someone can give me some hints.

Lanbo
  • 15,118
  • 16
  • 70
  • 147
  • I don't know what is the desired behaviour, but your speed v is always increasing, since your building an integral over a constant, and the position is increasing fast because you have p also on the right hand side. So I figure your particle is gone in a second... – martingw Jul 21 '12 at 14:31
  • Which is exactly the problem... what is your suggestion on `p`? – Lanbo Jul 21 '12 at 15:45

1 Answers1

1

With the little hint from @martingw, I was able to cook up this, which is quite what I was looking for:

star :: (Float, Float) -> SF (Float, Float) (Float, Float)
star p0 = proc (a, vel) -> do
    let (vx,vy)  = vel *^ (cos a, sin a)
    p <- clampS ^<< (p0 ^+^) ^<< integral -< (-vx,vy)
    returnA -< p

clampS (x, y) = (x `fMod` 800, y `fMod` 600)
Lanbo
  • 15,118
  • 16
  • 70
  • 147
  • Just note that you build up are large integral that you then later clamp. If you later want to slow down the star, it will take a long time before you see any effect. I had similar issues when modelling a ball... I can send you a snippet id you are interested. – martingw Jul 21 '12 at 18:55
  • I changed `clampS`, see above... I am slowly getting a feeling for this Yampa stuff, though I feel I'm quite alone with my persuing of it. – Lanbo Jul 22 '12 at 07:40
  • My experience was it takes a while to build up some intuition, especially with the iPre etc. functions. The mailing list is very helpful, though. – martingw Jul 22 '12 at 12:11
  • yeah I have no idea what `iPre` is supposed to do. – Lanbo Jul 22 '12 at 12:21