How do I change texture of face of a 3d object using code?

Not favoritedFavorited Favorited 0 favourites
  • 8 posts
From the Asset Store
Template for a basketball game with a 3D aspect (illusion of 3D)
  • Hello Constructors :)

    I generated instances of a 3d object using For Each loop. For some of these objects I'd like to change textures of certain sides (faces) of the objects using code. I seem to struggle to achieve that.

    The idea is a modification of a Free Demo game called "3D Maze Castle", where they populate 2d map using 2d objects, then use For Each loop to generate 3d objects based on the placement of the 2d objects.

    Here is what I did:

    * I have a 3d object created under Object Types called 'Cube01'. It has bevaviour Solid.

    * I have a 2d object created under Object Types called 'MapItem'. It has bevaviour Solid.

    * I placed instances of 2d item on the map.

    * Using code: (on start of layout) System -> For each MapItem -> System -> Create object Cube01 on layer Background at (MapItem.x, MapItem.y) ...

    * Using code assign a variable to 3d objects, inside the For each loop: Cube01 -> Set Cube01UID to MapItem.UID

    The above works ok.

    Now I tried to add the following code:

    * (on start of layout) Cube01 -> Cube01UID = 2 -> Cube01 -> Set Back face to use image of Hand (Hand in another object with a different texture)

    The program runs, but the last line doesn't seem to have any effect, the texture does not change.

    I tried replacing 'Set Back face to use image of' with 'Set color to rgbEx(0,0,0)', but it also has no effect under Preview.

    What did I do wrong? How can change texture of a selected face (let's say Back face) of 3d instances of an object for certain UIDs?

  • Here is a screenshot of the code section:

  • Guys, could someone please reply? Is this forum active? A little bit of guideline, any help will be fantastic. I'm kinda new to Construct, which seems like a great tool. We all learn.

  • Guys, could someone please reply? Is this forum active? A little bit of guideline, any help will be fantastic. I'm kinda new to Construct, which seems like a great tool. We all learn.

    Hello.

    Please upload the “*.c3p” file to the forum, and I will assist you.

  • Thank you for your assistance.

    Here you go, this is the screenshot of the entire project.

    Some of the lines were disabled as I tried to change the texture of a specific face, but it didn't work, as mentioned in the original post.

    It's nothing sophisticated, I just can't seem to get it to work to modify a selected face of a 3d object with code.

  • Thank you for your assistance.

    Here you go, this is the screenshot of the entire project.

    Some of the lines were disabled as I tried to change the texture of a specific face, but it didn't work, as mentioned in the original post.

    It's nothing sophisticated, I just can't seem to get it to work to modify a selected face of a 3d object with code.

    ....

    For example, I changed some of the cube's edges to a picture or tile.

    I added a comparison to the example.

    fex.net/s/oxbakm4

  • Would you kindly please post a screenshot of the Event sheet? I can't seem to download the file. I will figure it out once I can see the Event sheet, I think.

    Thank you. I highly appreciate your help. Construct 3 seems like a great tool, most stuff you can figure out, but when you get stuck, it's crucial to reach out for advise. Thanks!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Edit: I finally got your example and studied it! This is great. Much appreciated. This fully answers the original question.

    Thank you for showing multiple ways of achieving the result.

    I think the mistake I made, was that I didn't include the texture in a level. In other words, I wanted to change to a texture, which the engine didn't recognize.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)