Adding an Actor

Hello,
I’m having some difficulties setting an Actor down.
I am getting no error messages, and everything works perfectly fine, Except my Actor does not show up.

Route for file:

from direct.showbase.DirectObject import DirectObject

Script itself:

class World(DirectObject):

def __init__(self):
    
    self.Blaze = Actor("models/ralph",
        {"run":"models/ralph-run",
        "walk":"models/ralph-walk"})
    self.Blaze.reparentTo(render)
    self.Blaze.setScale(.2)
    self.Blaze.setPos(0,0,0)

Could someone possibly tell me what i’m doing wrong?
Much appreciated!

(models/ralph, models/ralph-run, and models/ralph-walk are not mine, and I take no credit for it.)

-Luna

Hmm… I don’t see code positioning your camera. Do you have any such elsewhere? If not, you might find that your camera is still at (0, 0, 0), and thus inside the model that you’re trying to view.

Try this:

# Somewhere early on in your code, perhaps towards the top
# of your "World" constructor
base.disableMouse() # Disable the default camera control

# ... later:
base.camera.setPos(0, -5, 0) # Or whatever y-value works

By the way, when posting code, trying using the “code” tags (either via the button labelled “Code” when posting or editing a reply or by simply putting the appropriate tags - [ code ] and [ /code ], minus the spaces within the brackets, I believe - around the relevant text). It should allow you to post code in a monospaced font while preserving indentation, and thus keeping scoping clear and code more legible. For example:

[ code ]
Some code
Some indented code
# A comment
[ /code ]

without the spaces within the brackets should become:

Some code
    Some indented code
    # A comment

Even while I used this, I have tried relocating the camera view on the default, but I would rotate and re-zoom. So I’m unpositive that’s the problem, at all.
I will however, take it into consideration for future usage, so thank you.

About the Code tags, I remember using something like it way back on the smaller game programming using GScript, Called HTML tags, so thanks again.

Overall with my code, you don’t happen to see anything wrong with it???
I’m trying to do this, and maybe, just maybe it’s not working because the model for the Actor is misplaced/the file is not loading properly?
So let’s pretend this is the case, and I were to make my own Animations,
How would I import this? Assuming its on my desktop.

All right, I’ve taken another look (including running your code on my end), and, presuming that the code that you’ve posted is the entirety of the project thus far, I see a few problems.

First, I don’t see any code instantiating your “World” class (that is, creating an object of that type), or calling the “run” method, which I believe starts the game. Without the latter, I’d expect the code to run, but produce nothing - not even a window. Is that what you’re seeing?

Second, my version seems to want me to import Actor and DirectStart (the latter provides “base”, I think).

Finally, I am indeed having trouble loading Ralph using just your code; perhaps try the panda model instead:

self.Blaze = Actor("models/panda-model",
                   {"walk": "models/panda-walk4"})

(The panda does seem to work on my end.)

Yes, I have used:

class Character(DirectObject):

In mine. Not sure if it has to be world, but I was told it can be anything as long as it has something of the sort connecting them in parenthesis afterwards, in this case: DirectObject.

I do also have Actor, I however have not tried this yet, as I won’t be on until some time tomorrow. Just want a heads up on what I’ll be fixing tomorrow.

I have Actor, DirectStart, The class to put in the Actor, and run() at the end.

Going into short detail, you think maybe I could use my same code, but use the panda modle instead, and it may work? Or is their more to it than that, do you think?

I don’t see the need to inherit your object from DirectObject since you’re not using any self.accept to accept events.

As Thaumaturge pointed out, you don’t seem to be instantiating your Character class anywhere. Keep in mind that you should store a reference when instantiating it, otherwise it will go out of scope and get garbage collected (which would be responsible for your actor no longer animating).
If you don’t know what that means, I suggest that you go and learn the basic Python concepts first.

Once you’ve done that, try substituting the panda model, using the lines that I gave above, and see what happens - it seems to me to be a quick, simple test, at the least.

Bear in mind that you may still want to move the camera, either by placing it in code or using the built-in camera controls, and that the panda model is enormous, I believe, so you may want to scale it down even more than you are already.

Thanks guys for the help<3.
I placed down

World()

Before run, instead of map().
I then removed

self

From everything, so it’d just be something like:

blaze = Actor("models/panda-model",
    {"walk": "models/panda-walk4"})

Rather than:

self.blaze = Actor("models/panda-model",
    {"walk": "models/panda-walk4"})

It now works and errors are no longer:)
So thank you both.

I’m glad to have been of service. :slight_smile:

One thing in your solution does concern me, however: your removal of the use of “self”. The effect of that should be to change those variables from instance variables (available anywhere within an instance of the class) to local variables (available only within that scope - in the case of “blaze”, this should be the init method).

That removing “self.” helped implies that there may be a problem elsewhere. If you’d like, perhaps it would help for you to post the entirety of your code (presuming that it’s not too much for a reasonable post).

(I note that in your new code you write “blaze” with its initial letter in lower-case, while previously it was in upper-case, I believe - could it perhaps have been that change that had the positive effect that you’ve seen, rather than the removal of “self.”?)