# Two questions, camera relative position and intervals

Hi to all,
I was making a simple game, where a character (in my case, sonic) can run around the world. I used intervals to move the character, for example.

``````    girarE = sonic.hprInterval(1,Point3(5,0,0),other=sonic)
girarE.loop()``````

but when I use the interval to move forward

``correrR = sonic.posInterval(1,Point3(0,-5,0),other=sonic)``

in the game it runs, but it doesn’t run all the time at the same speed, it makes a light decrease in speed. I don’t know why is this happening :S

Well, my other problem: [I solved this remaking my script, I don’t know what I was doing wrong, butnow it works]

Ok, these are my two questions. Thanks for reading the post

Movement looks pretty steady to me when I try it.

David

Do you mean it’s a bug of my computer?

No, I mean I don’t understand the problem, and I furthermore suspect that whatever problem you’re seeing isn’t related to the lines you’ve posted. There might be something else that’s causing the speed change you’re reporting; or maybe you’re misunderstanding what you’re seeing.

It is true that, over a period of time, you will gradually lose precision in the relative operations (moving a node relative to itself over and over again). It would be better to use a different mechanism, for instance, compute the target destination explicitly, and lerp to that, rather than using the other= parameter to the posInterval. Using the other= parameter is fine for short-lived intervals, but if you plan to loop the interval continuously, it can cause problems eventually.

David

Thanks, I thought that the problem was that, but I don’t know how to do what you said: "compute the target destination explicitly, and lerp to that, rather than using the other= parameter to the posInterval. " Is this in the manual? :S
Well, I’ll keep trying. I’ll take a look at the sample programs.

I think i know how to solve this, but I need some help xD.

I tried lots of things to move the character, and I saw, that the speed of the character is progressive, it begins slow, and it speeds up progressively (i don’t know if progressively it’s correct in english) and when the interval restarts, it goes slow. my question is: is there some way to make an interval begin and end at the same speed?, I found something about the blendType method, but it don’t works… is there some way to do this?
EDIT: sorry for the double posting, I thought I was editing :S

If you don’t specify blendType, or if you specify blendType = ‘none’, the interval will move at a constant speed. It only speeds up and slows down if you specify some other kind of blendType.

So, I still don’t know what you’re referring to, exactly.

David

I don’t know what happens, but I have no specifed the blendType, and it speeds up :S
It can be that the problem is when I define the key input?

``````def run():
sonic.loop('run')
global correrR
runR = sonic.posInterval(5.0,Point3(0,-25,0), other = sonic)
correrR.loop()

def stop():
sonic.play('stop')
runR.pause()

sonic.accept('arrow_up', run)
sonic.accept('arrow_up-up', stop)``````

Hmm, I bet you’re starting up multiple copies of this interval, and not pausing the old ones properly when you start up a new one.

For instance, it’s suspicious that you call correrR.loop() but runR.pause(). Why the different names?

If you have multiple intervals running at once, it will speed up.

David

The multiple names is not the error, because in spanish, correr is the verb run, and I traslated the names of the code before posting it, but I missed that one.
I think I will make the movement system different… Is a good Idea to use a while block than repeats sonic.setPos(sonic,0,-5,0) while the variable running it’s true?

-you shouldn’t use ‘while’ in most cases. everything that stops the script progress will freeze the game. let a function (keypress) set a variable to true and another (movement) check it each frame.

Ok, i think I understood it. But the second function must be a task, right?

Dunno what you mean, but here’s some sample code:

``````from pandac.PandaModules import KeyboardButton
SPEED = 5.0

def movementTask(task):
ver = base.mouseWatcherNode.isButtonDown(KeyboardButton.up())
ver -= base.mouseWatcherNode.isButtonDown(KeyboardButton.down())
hor = base.mouseWatcherNode.isButtonDown(KeyboardButton.right())
hor -= base.mouseWatcherNode.isButtonDown(KeyboardButton.left())
ver *= globalClock.getDt() #Framerate independent
hor *= globalClock.getDt()

sonic.setPos(sonic, hor * SPEED, ver * SPEED, 0)
return task.cont

taskMgr.add(movementTask, "Move sonic blahblah")``````

Thanks very much for the sample code!!!
I’ll made a script like that in my game, and now it runs at the same speed all the time thanks very much to all for answering me