00:00
00:00
Newgrounds Background Image Theme

Vaittus just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Modifying the V-Cam (As2)

1,437 Views | 13 Replies
New Topic Respond to this Topic

Modifying the V-Cam (As2) 2014-01-21 16:39:08


DEEEEEEEEEEEEEEEEAAAAAAAAAAARRRRRR Forum.

I have encountered an issue with my V-cam in my 2d scroller.

I want the Vcam to have my character in the lower middle of the screen, walking on my ground, which is at the bottom of the screen.

Now, the V-Cam if programmed so that if it follows an object (code below), it follows the object (player) being in the centre of the screen, having the ground floating in mid air with the character standing on it. Is there any way to modify the code in the Vcam (or code below) to make it follow a bit over the player, instead of following its registration point, which is at the feet of the character.

Code:
onClipEvent (enterFrame) {
_y += (_root.player._y-_y)/1;
_x += (_root.player._x-_x)/1;
}

Modifying the V-Cam (As2)


BBS Signature

Response to Modifying the V-Cam (As2) 2014-01-21 17:10:29


At 1/21/14 04:39 PM, w00t634 wrote: Code:
onClipEvent (enterFrame) {
_y += (_root.player._y-_y)/1;
_x += (_root.player._x-_x)/1;
}

This code makes no sense.
On what symbol is it?
It should not move anything but itself, even.

Response to Modifying the V-Cam (As2) 2014-01-21 17:30:14


A bit of brainwashing advice:
Remove your V-Cam. You don't need it. It's for animations.

What is the MATH that drives the functionality of a V-Cam? It's really simple.
If you know how to solve basic linear mathematical equations (studied in third grade of school), then you are able to find root x of an equation like

x+5=3

In this case

x=3-5=-2

To be more abstract

if
x+a=b
then
x=b-a

You seem to write without too many grammar mistakes, so I assume you understood this.

Now the nested coordinate systems. Every movie clip, including _root, which is a movie clip, is a coordinate system. When you put a movie clip inside a movie clip, we may talk about nested coordinate systems, because you put one coordinate system into another.
Coordinates of nested coordinate systems, assuming that none of the movie clips are rotated, scaled or skewed, are additive.
It means that a coordinate of a point inside a movie clip on the stage is the sum of coordinates of all parents of that movie clip plus the coordinate itself.
In this case, the player has its parent as _root, and _root has no parent.
I've mentioned some stage here - it is the application screen. You see, you can move _root like any other movie clip, and by moving it you move all contents of your flash application. Stage is the global, basic container of everything, which cannot be moved. Stage's coordinates refer to pixels on the screen.

player_on_stage = player_in_root + root_position

Here, player_in_root is the coordinate of the player movie clip inside _root, and root_position is the _root's coordinate (on stage).
The projection of the player onto the stage is the sum of its position inside _root and of _root's coordinate.

This formulae breaks into X and Y formulaes, meaning

player_on_stage_X = player_in_root_X + root_position_X
player_on_stage_Y = player_in_root_Y + root_position_Y

So what you want is for the player movie clip to always be positioned in the center of the stage, offset downwards by, let's say Q pixels (where Q is a number less than half the height of the screen).
Also, let's assume that height of the screen is scr_H (for example, 400) and that width of the screen is scr_W (for example, 550).
THEN, this is what you want:

player_on_stage_X=scr_W/2;
player_on_stage_y=scr_H/2 + Q; //we're adding, because Y axis is directed DOWNWARDS

All these are mathematical equations.
Now, you need to solve them and find these two values:

root_position_X
root_position_Y

Now, find them.

Very good, you are done.
Now, you need to translate the math into code.
root_position_X becomes _root._x
root_position_Y becomes _root._y
scr_W=550
scr_H=400
player_on_stage_X is simply player._x
player_on_stage_Y is simply player._y
And you need to do that every frame.
That's it.

Response to Modifying the V-Cam (As2) 2014-01-26 09:10:08


take a look at the piece of code you got there on the vcam and try to learn how to edit it;

onClipEvent (enterFrame) {
_y += (_root.player._y-_y)/1;

vcam follows player up and down

_x += (_root.player._x-_x)/1;

vcam follows player left and right

}

are the player moving up and down a lot? then what you might want is to add like 150 pixels
space between the player registration point and the vcam registration point like this:

_y += (_root.player._y-_y-150)/5;

if not, then why not just move the vcam when the player reach certain points?
replace the "_y code" with the code below and try it.

if (_root.player._y < _y-40){
	_y -= 8;
}
if (_root.player._y > _y+170){
	_y += 8;
}

feel free to experiment with +, -, and numbers.

- KT

Response to Modifying the V-Cam (As2) 2014-01-26 11:26:45


At 1/26/14 09:10 AM, Krizy wrote: feel free to experiment with +, -, and numbers.

- KT

Experimenting does not beat superb math knowledge. You can write stuff on paper and then program everything perfectly from on the first try without any experiments!
When?! When will people start taking math seriously?!

Response to Modifying the V-Cam (As2) 2014-01-28 15:45:07


At 1/26/14 11:26 AM, kkots wrote:
At 1/26/14 09:10 AM, Krizy wrote: feel free to experiment with +, -, and numbers.

- KT
Experimenting does not beat superb math knowledge. You can write stuff on paper and then program everything perfectly from on the first try without any experiments!
When?! When will people start taking math seriously?!

experimenting trains your abality to visualisation math in your head. I taught myself everything just by experimenting and now I don't have to do anything on paper and don't even have to think about it anymore.
Instead of struggling with it, just have fun with it! it will get you really far.


.

Response to Modifying the V-Cam (As2) 2014-01-28 22:01:41


Whoa whoa whoa, these guys are making this sound way too complicated. Just stop getting the vcam to follow the y axis, only follow the x axis and move the vcam mc on the stage and get it so it isn't showing any of the background below the ground.

Like this:

onClipEvent (enterFrame) {
_x += (_root.player._x-_x)/1;
}

If you have no idea what I'm talking about just pm me and I'll come back to this thread


Trying to post in topics that have no replies. Trust me it's a horrible feeling when nobody replies to your topic :{

Response to Modifying the V-Cam (As2) 2014-01-28 22:04:37


At 1/28/14 10:01 PM, DannyDaNinja wrote: Whoa whoa whoa, these guys are making this sound way too complicated.

That was not necessary to say. Could have just given your advice, without mentioning others.

I can help you understand the math behind v-cams, too.

Response to Modifying the V-Cam (As2) 2014-01-29 17:29:02


onClipEvent (enterFrame) {
_y += ((_root.player._y+200)-_y)/1;
_x += (_root.player._x-_x)/1;
}

the 200 is just an example number. You can either just add or subtract until your happy with the height of the camera or...

-go to window, open the info panel.

-arranged the Vcam and player how you would like them to look when it runs.

-once they are arranged click on player. the info should show his "y" write it down

-do the same for the vcam

-now just put the difference where the 200 is.

hope that helped!

Response to Modifying the V-Cam (As2) 2014-01-29 21:13:28


At 1/21/14 04:39 PM, w00t634 wrote: _y += (_root.player._y-_y)/1;
_x += (_root.player._x-_x)/1;
At 1/28/14 10:01 PM, DannyDaNinja wrote: _x += (_root.player._x-_x)/1;
At 1/29/14 05:29 PM, OOGIDIBA wrote: _y += ((_root.player._y+200)-_y)/1;
_x += (_root.player._x-_x)/1;

Why are you guys dividing by 1?

Response to Modifying the V-Cam (As2) 2014-01-29 21:21:00


At 1/29/14 09:13 PM, Diki wrote:
At 1/21/14 04:39 PM, w00t634 wrote: _y += (_root.player._y-_y)/1;
_x += (_root.player._x-_x)/1;
At 1/28/14 10:01 PM, DannyDaNinja wrote: _x += (_root.player._x-_x)/1;
At 1/29/14 05:29 PM, OOGIDIBA wrote: _y += ((_root.player._y+200)-_y)/1;
_x += (_root.player._x-_x)/1;
Why are you guys dividing by 1?

lol I'm assuming he has it there so he can smooth the camera movement but yeah it'd have to be more then 1. I was more concerned with helping him fix his position problem than questioning his code.

Response to Modifying the V-Cam (As2) 2014-01-29 22:19:18


At 1/29/14 09:21 PM, OOGIDIBA wrote: lol I'm assuming he has it there so he can smooth the camera movement but yeah it'd have to be more then 1. I was more concerned with helping him fix his position problem than questioning his code.

If you just missed that when you plugged an integer into his code, it's fine, but at some point someone wrote that with the denominator as 1, which means that person doesn't understand how dividing works. Although I don't think we'll find out where the OP got that code from, or if he wrote it himself, since he seems to have abandoned this thread. But if he did write it I think it's worth explaining that dividing by 1 serves no purpose.

Response to Modifying the V-Cam (As2) 2014-06-26 11:42:49


At 1/29/14 05:29 PM, OOGIDIBA wrote: onClipEvent (enterFrame) {
_y += ((_root.player._y+200)-_y)/1;
_x += (_root.player._x-_x)/1;
}

the 200 is just an example number. You can either just add or subtract until your happy with the height of the camera or...

-go to window, open the info panel.

-arranged the Vcam and player how you would like them to look when it runs.

-once they are arranged click on player. the info should show his "y" write it down

-do the same for the vcam

-now just put the difference where the 200 is.

hope that helped!

Hey dude thanks! This was exactly what i was looking for!
Thanks, helped a lot!
You are my hero :D


BBS Signature

Response to Modifying the V-Cam (As2) 2014-06-26 15:09:52


At 1/26/14 09:10 AM, Krizy wrote: take a look at the piece of code you got there on the vcam and try to learn how to edit it;
onClipEvent (enterFrame) {
_y += (_root.player._y-_y)/1;
vcam follows player up and down
_x += (_root.player._x-_x)/1;
vcam follows player left and right
}
are the player moving up and down a lot? then what you might want is to add like 150 pixels
space between the player registration point and the vcam registration point like this:

_y += (_root.player._y-_y-150)/5;

if not, then why not just move the vcam when the player reach certain points?
replace the "_y code" with the code below and try it.

if (_root.player._y < _y-40){
_y -= 8;
}
if (_root.player._y > _y+170){
_y += 8;
}

feel free to experiment with +, -, and numbers.

- KT

Hmm...

Yes! This seems to work really good!
Thanks, the game looks a lot better when the camera actually follows the player around when jumping!
Thank you!


BBS Signature