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.
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.
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.
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.
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