Sticking camera to a projectile

0 favourites
  • 2 posts
From the Asset Store
Simple and easily editable template for a dynamic camera that zooms in and out based on how far apart the players are.
  • I'm trying to lock the camera onto a projectile, and having trouble.

    I have the camera assigned to an invisible sprite.

    I can get this effect easily by Pinning the camera to the projectile On Creation, then moving the camera back after the projectile lands. But the problem with this is Pin is much too inaccurate and has noticeable lag when moving at high speed like this.

    I can use Set Position to Another Object every frame to set the camera on top of the projectile while it's flying, but I don't know of a way to distinguish one instance of the object from another like On Creation allows, so when an earlier projectile is stuck in the ground it can't find the proper one to stick to.

    I could probably add the camera behavior directly to the projectile, then create a secondary version of it with no camera behavior to replace it with after it lands, destroy the original camera after the the projectile is launched and respawn it after the projectile is replaced.

    But I have some complex actions going on with the projectile and replicating it all on the replacement projectile would create some pretty messy and complicated events.

    As one example, the projectile is a giant ballista bolt, and if an enemy is hit they get impaled and travel with it. I don't even know how I would re-pin that specific enemy to that specific bolt, because of my earlier issue of distinguishing one instance of an object from another without using something like On Collision or On Destroyed.

    Does anyone know of a good way to do this?

    I could use Pick Nth Instance to find the newest projectile I think, but I have no idea how to automatically acquire the newest one.

    Edit: I tried using Pick Nth Instance with Object.Count to get the highest number, but I then realized I have no idea how Pick Nth Instance is supposed to actually "pick" an instance at all, and can't get it to work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I figured it out myself.

    First of all, System > Scroll to Object is better if you have multiple things to track the camera on. Apparently the Camera behavior for objects is just meant for when you have a single mobile point of focus, like a Player sprite in a platformer.

    I fixed the issue by setting a variable whenever the projectile was created, then when the variable reads true I have the sub-event Pick Nth Object > Object.Count-1 (Object being the name of the projectile), then as the action for that event I have it Scroll To Object.

    When the object lands or is destroyed, I just set the variable back to 0 and Scroll To back to the ballista once.

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