Search Results

Thursday, July 5, 2012

2D Blender Game Engine Tutorial Part 2

Hey. Here's another part to the 2D BGE video tutorial series that I started earlier. This part goes into movement, animation changing, mirroring the sprite based on facing, and other things.



Here's the source. Have fun!

17 comments:

  1. Um... im still trying to figure out how buster works havent got any progress... for my game to be on web.. it very important that i do.. well ive downloaded buster and installed but theres nothing to indicate what i should do .. the only thing that looks like a program in the buster file is the player.exe and that dosent do anything help me out.... my frend if you can... would be a help.. if someone in the world would post a video on youtube how to do the intire prosses because there is none... ive looked everywere.. thanks..

    ReplyDelete
    Replies
    1. Unfortunately, I haven't worked with Burster, so I don't know of the process to develop a game for use with it. You would probably do well to check out BlenderArtists - some BGE users who have worked with Burster should hang out there. You'll probably get pointed in the right direction at least.

      Delete
  2. Argh, neither FF nor Opera are showing any video here. Am I missing something?

    ReplyDelete
  3. getting an error :/

    keyboard = logic.keyboard.active_events
    AttributeError: 'SCA_PythonKeyboard' object has no attribute 'active_events'

    how do I fix it?

    ReplyDelete
    Replies
    1. You have to have a more recent version of Blender to use that variable, as it was added recently. However, since you have to check to see if the event is present anyway, it's probably just easier to use logic.keyboard.events and bypass the 'if keyboardkey in active_events' step altogether. I'm most likely going to remake these tutorials to be more accurate and efficient altogether.

      Delete
    2. Ah, old laptop still not quite up to date. That'd probably explain it ^^

      Delete
  4. This video(as well as part one) was great. I'm just starting to learn Python because I wasn't getting the results I desired from logic bricks. Although I am working on a 3D implementation, your explanations of the code was very useful to help me achieve that. There is one issue I'm currently stuck on: detecting if the player is on the ground without using material or floor properties(for jumping or preventing 'additional' forward/back/strafing movement while player has no ground under his feet). I didn't want to use props or mats because of unexpected results when the player touches the material from the sides. I thought of checking for zero linear velocity in the Z axis but can't quite figure out how to implement it - ie, Only jump if linear velocity Z is zero but as soon as it jumps its linear velocity Z is no longer zero and hence the jump stops immediately. Any suggestions?

    ReplyDelete
    Replies
    1. Hello. Thanks a lot for watching my videos and I'm glad that you like them.

      For the jumping, you would usually use linear velocity to set the speed of the object in the Z-axis high, and let gravity take over. You would check to see if there's actually ground underneath the object, as well, since the Z-axis's speed of the object can get to 0 in the air. As for your problem, you're basically looking at either:

      A) Using a separate object for detecting ground collision (i.e. one positioned under the object), or

      B) Using a ray cast to check for the ground underneath the object's feet.

      Both aren't bad, but there are side effects. Method A is good because it allows you to have a large area for testing for the ground, but it doesn't give you any information about exactly how far away from the ground the player is at any time.

      Method B is good because it gives you the information about where the player is in relation to the ground (the ray cast returns the hit point of the ray on the polygon), but the down-side is that it's thin, so the object would have to have ground directly underneath his center (or wherever the ray is aiming) for him to be able to jump.

      Mixing the two can be useful, though.

      Delete
    2. Thank you for the reply. I guess I had been thinking along the lines of your suggestion A by using maybe a circle plane at the base of the player's bounding box and using that as a ground detector. Like I said, I'm new to Python and am just starting to learn how to manage a single object with a script. Figuring out how to integrate another object as it's child object seems a little daunting and not sure where to start. Learning as I go might be a little counter-intuitive but it the only way I know how. I will do some reading and searching at the BA forum to figure this out. If you have any tutorials similar to that subject, I would appreciate it very much. Thanks again.

      Delete
    3. I don't have a tutorial specifically for just that, but you can easily get a child of a parent with objects.children, or with the scene.objects['objectname'] method.

      I would just parent the ground object to the player object (so that it stays with him), and give the ground object a collision sensor set to a ground property. Then, with the ground object and the player object selected, connect the ground object's sensor to the player object's Python controller. You can then just refer to the sensor as usual (cont.sensors).

      Delete
    4. It took some trial and error. I had to make the ground sensing object a Physics Type: "Sensor" in order for it to detect collision as a child - which is fine for me as that's all I need it to do is be a sensor. Now the player object knows that if it's in the air, it can't jump again or control itself in the normal way (forward, backpedal, strafe).

      I did add a little bit of video game physics like being able to nudge slightly while your in the air to have a little control(or stand up against an obstacle, jump straight up and push forward to get on to it). I also added the ability to cancel out of the jump at any time. Doing this zero's out your linV in all axes so you can drop straight if you want to.

      Next up, I'll try to add mouse movement and strap a camera to it. It's already starting to feel like a decent FPS layout.

      Your help and just reading in the forums (member name is sodsm_live) have really helped me get back in to this.

      Delete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. One can get an object's 3D location by getting the object, for example through the scene.objects list, and then getting its worldPosition property:

    sce = logic.getCurrentScene()

    food = sce.objects['Food']

    print (food.worldPosition)

    ReplyDelete
  7. hi! I am having some problems whit this... When i open your source and press the letter "P" i cant see the pixel guy, i only see a white plane. Can you tell me how can i fix this!? thanks!

    ReplyDelete