Complex camera swap system. How do I translate X and Y locations? (Solved)

0 favourites
  • 7 posts
From the Asset Store
Full game Construct 2 capx code source to post on Google Play
  • Hi everyone, I'm wondering how to translate these X and Y locations of different characters from a side scroll perspective to other 2D perspectives, and vise versa. Here's a few examples of the other perspectives that I have planned. Any help is greatly appreciated. : )

  • Can you explain what you’re after a bit more? It’s not clear to me.

    Your images are different views of 3D meshes. So if you placed cubes down and adjusted the camera you can get the same look. But your descriptions made it seem like you’re after something else

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry about that. Let me explain what I mean.

    The character's are in a side scroll environment much like what you would find in a beat em up game. I would like to implement a another perspective by changing camera's view to a different angle, but in a 2D space. Adjusting each character's X, and Y values to match the new camera's view, and to check if that character's in the camera's line of sight. Think of this like a movie set. Here's an example of what I'd like to accomplish.

  • So you just want to change the view? You can use the 3d camera object to do that to some extent. You can position objects xy and zElevation.

    Control wise all the movement behaviors are 2d on the xy plane so you'll need to do the z axis motion with events.

    If you don't want to use 3d and instead want to do the rotation/perspective with math and just sort the objects in 2d then the two building blocks for that are:

    1. Rotation of a position around a center. Here it does it on the xy plane but you can do it on the xz or yz plane too. The equations are the same, just change what axis is used.

    newX = (x-centerX)*cos(a) - (y-centerY)*sin(a) + centerX

    newY = (x-centerX)*sin(a) + (y-centerY)*cos(a) + centerY

    2. perspective transform and scaling. Here k is some scaling factor that adjusts the perspective. Keep in mind you'll want to hide objects with a z<1 as they are behind the camera, and you'll need to sort the objects by z.

    screenX = k*(x-scrollx)/z + scrollx

    screenY = k*(y-scrolly)/z + scrolly

    objScale = k/z

  • Thank you, this formula is exactly what I need! : ) I was able to get the characters a little closer to where I need them to be, but I'm having a little trouble understanding what k, z, and a means. I'm very sorry to ask for your help again, but would you mind explaining how the formula works please?

  • Well k is just an arbitrary number. Having k=1 may make the perspective effect too severe, but a higher number such as 500 would make it more subtle in a reasonable way. If more careful about the units it relates to the field of vision of the camera.

    z is the third dimensional position of an object. I know we are dealing in 2d but to have the perspective we need to know how far into the screen an object is to scale it.

    a is just the amount of degrees you wanted to rotate.

    Here is a possible example but i got a bit carried away beyond the basic ideas. I guess 3d tends to snowball depending what you're doing. The meat of it is event 15. It sets the camera orientation, transforms the object positions from that orientation, applies a perspective transform, and finally zsorts everything.

    dropbox.com/s/oggk1776al45ka1/3d_camera_events.capx

  • AHHH!! Thank you so much R0J0hound. This is exactly what I need. The example you sent instantly fixed all of my problems I've been struggling, and worried about for months now. I can already tell that I'll be using this formula for many years.

    Thanks again! : )

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