Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

[Help] Smoothly changing camera boundaries


MrKsoft

Recommended Posts

I am adding a boss area into the second act of my game but I am coming across difficulty in making the camera move into it properly.

How would you recommend making the camera smoothly lock into the center of the 320x240 boss section of the level? All the ways I have tried made it move to the center of the boss area immediately, which is slightly disorienting and very unprofessional/ugly.

Link to comment
Share on other sites

I tried doing this in an event, which disabled the camera group, set the new limits, and reactivated the camera group (I checked, and they ARE happening in that order) but it merely does the sloppy jumping and doesn't move into it as it does in the old classic games.

Also, I realized that I had an implementation of linear interpolation in an unfinished game of mine, but efforts to try to adapt it for SW seem unsuccessful (I end up battling against the already-established camera events)

Link to comment
Share on other sites

"Linear Interpolation" sounds like a complicated term, but it's really quite simple: it's taking two points and forming a smooth line between them. The formula per-dimension is as simple as you're going to find, namely:

point = starting_point + (ending_point - starting_point) * percent_done/100;

You can replace "percent_done/100" with "current_step/max_step" or any such thing.

There are a number of different ways you can do it in the Sonic Worlds engine. Since I can't find the Sonic Worlds engine on my computer, I'll just say the most general way: and that'd be to start the boundry as the boundry you want it to be + the width/height of the screen at all points. Namely, you'd have camera_maxX + screen_width (or w/e the variables are called) as the maxX starting point, camera_minX - screen_width as the minX starting point and the same with Ys.

You would have 4 starting_points and 4 ending_points (one for the minx, maxx, miny, and maxy) and 1 current_step and max_step. Using those, you would apply the above formula with current_step starting at 1 and adding 1 to it every frame to find the max/min x/y to put into the engine.

Link to comment
Share on other sites

Er... that's all there is to it.

current_point = starting_point + (ending_point - starting_point) * factor_done;

Where factor_done is between 0 and 1.

For example, if you want to create a smoothly transition an object's position from it's current position to a new position (say 0,0) over the course of 30 frames:

First you would define the starting_points and ending points for both the x axis and y axis. You'd also initialize a variable to keep track of what frame you're on, and you'd also say how many frames you want this to be over. I guess you'd also turn a flag or something to signify that you're interpolating on:

starting_x = X("object")
starting_y = Y("object")
ending_x = 0
ending_y = 0

current_frame = 0
max_frames = 30

interpolating = 1

Then, every step, if interpolation is on, you'd add 1 to the current_frame and determine the object's X and Y position from the above formula:

current_frame = current_frame + 1

X("Object") = starting_x + (ending_x - starting_x) * current_frame / max_frames
Y("Object") = starting_y + (ending_y - starting_y) * current_frame / max_frames

Then, if interpolation is on and current_frame is bigger or equal to max_frames, you'd set the X and Y to the ending point and turn interpolation off:

X("Object") = ending_x
Y("Object") = ending_y

interpolation = 0

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...