How to make background move in relation to player

0 favourites
  • 3 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • How do you keep a player from rotating in relation to the background or enemy sprites? For example, when you press WASD keys, the player object will normally move up down, turn left or right, what if I want to keep the object from turning, but instead the background is the one that does the turning. The player object remains unmoved. I can keep the object at centre screen using Scroll to behavior buy that's about all it can do. Any idea? Please help. Thanks

  • maybe you could make to background rotate when you press the directions and have the sprite rotate in the opposite direction?

    just an idea, im new to this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To achieve the effect where the player object remains stationary and the background rotates, you can implement the following steps in Construct 3:

    1. **Keep the Player Object Centered:**

    - As you've mentioned, use the "Scroll To" behavior on the player object to keep it centered on the screen.

    2. **Rotate the Background:**

    - Instead of rotating the player object, rotate the background layer or the enemy sprites. You can achieve this by manipulating the angle of the layer containing the background or the enemies.

    Here's a detailed step-by-step approach:

    ### Step 1: Add Scroll To Behavior to Player

    1. **Select the Player Object:**

    - Click on your player object.

    2. **Add Behavior:**

    - In the properties panel, click on "Behaviors" and then "Add New Behavior."

    - Select the "Scroll To" behavior to keep the player centered on the screen.

    ### Step 2: Rotate the Background or Enemy Layer

    1. **Create a Background Layer:**

    - If you haven't already, create a new layer for your background.

    - In the "Layers" panel, click on "Add Layer" and name it "Background."

    2. **Rotate the Background Layer:**

    - To rotate the background layer based on player input, you need to update the layer's angle in response to the WASD keys.

    ### Step 3: Add Event to Rotate Background Layer

    1. **Open the Event Sheet:**

    - Go to the event sheet where you handle player input.

    2. **Add Keyboard Events:**

    - Add events to handle the WASD keys.

    - For each key, update the angle of the background layer.

    Here's an example of how you might set this up:

    ```plaintext

    Event: Keyboard -> On W key pressed

    Action: System -> Rotate layer "Background" by -1 degrees

    Event: Keyboard -> On S key pressed

    Action: System -> Rotate layer "Background" by 1 degree

    Event: Keyboard -> On A key pressed

    Action: System -> Rotate layer "Background" by -1 degrees

    Event: Keyboard -> On D key pressed

    Action: System -> Rotate layer "Background" by 1 degree

    ```

    ### Step 4: Fine-Tune the Rotation

    You may want to adjust the rotation amount or implement smooth rotation using variables for a better effect.

    Example of smooth rotation using a variable:

    1. **Create a Variable for Rotation:**

    - Create a global variable, e.g., `Global number RotationSpeed = 0`.

    2. **Update the Variable on Key Press:**

    - Instead of directly rotating the layer, update the `RotationSpeed` variable based on key presses.

    ```plaintext

    Event: Keyboard -> On W key pressed

    Action: System -> Set value RotationSpeed to -1

    Event: Keyboard -> On S key pressed

    Action: System -> Set value RotationSpeed to 1

    Event: Keyboard -> On A key pressed

    Action: System -> Set value RotationSpeed to -1

    Event: Keyboard -> On D key pressed

    Action: System -> Set value RotationSpeed to 1

    ```

    3. **Apply the Rotation in Every Tick:**

    - Use the `RotationSpeed` variable to rotate the background layer smoothly.

    ```plaintext

    Event: System -> Every tick

    Action: System -> Rotate layer "Background" by RotationSpeed degrees

    ```

    4. **Reset RotationSpeed when No Key is Pressed:**

    - Reset `RotationSpeed` to 0 when no movement key is pressed.

    ```plaintext

    Event: Keyboard -> On key released

    Action: System -> Set value RotationSpeed to 0

    ```

    By following these steps, you can create a game where the player object remains stationary while the background rotates based on player input, giving the desired effect.

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