The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 5:41 am

Forum rules


IMPORTANT

This Forum is for Flash related questions ONLY! Do not ask questions about spriting, Game Maker, Photoshop, or anything else not related to Flash.



 [ 6 posts ] 
[Request] Virtual Camera follow Character 
Author Message
User avatar

Joined: Tue Oct 28, 2008 1:37 pm
Posts: 300
how do you make the camera always follow your charecter

_________________
Image
super smash bros blits(working title)-1% done
new flash game


Wed Apr 29, 2009 1:39 am
User avatar

Joined: Mon Aug 11, 2008 1:09 pm
Posts: 166
Location: England lol
Gender: Male
Currently Playing: Minecraft
If the game isn't heavily graphics based you could try something called a VCam - its probably the easiest solution and is just a movie clip that can be programmed to follow anything, resize, recolour etc... Otherwise there are a few tutorials on the net that do it by code. If I can find the links i will post them here.


Wed Apr 29, 2009 12:23 pm
WWW
User avatar

Joined: Tue Oct 28, 2008 1:37 pm
Posts: 300
ive made a v cam now but alls i need to know is how to make a movie clip follow another one
edit:could some one please give me the code to do this PLEASE!!! :mrgreen:

_________________
Image
super smash bros blits(working title)-1% done
new flash game


Wed Apr 29, 2009 2:40 pm
User avatar

Joined: Mon Aug 11, 2008 1:09 pm
Posts: 166
Location: England lol
Gender: Male
Currently Playing: Minecraft
Code:
onClipEvent(enterFrame) {
  speed = 10;
  _x += (_root.character._x - _x) / speed;
  _y += (_root.character._y - _y) / speed;
  updateAfterEvent();
}


That should work if you attach it to the VCam Movie Clip


Wed Apr 29, 2009 5:23 pm
WWW
User avatar

Joined: Wed Apr 29, 2009 11:28 pm
Posts: 323
Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
x2i wrote:
Code:
onClipEvent(enterFrame) {
  speed = 10;
  _x += (_root.character._x - _x) / speed;
  _y += (_root.character._y - _y) / speed;
  updateAfterEvent();
}


That should work if you attach it to the VCam Movie Clip

That has got to be the largest example of overkill I have ever seen in code. Not only that, but you made a number of mistakes. Also, the Vcam stutters if the movements are controlled by actionscript, I know from experience.

To get the "camera" following the character in the dead center of the screen just have this code play every frame (Why on earth would you use clipevent?).

Code:
_root._x = _root.character._x - (_root._width/2);
_root._y = _root.character._y - (_root._height/2);


To offer a sounder solution to the previous attempt which tried to get it to move smoothly (poor method, it leads to the velocity of the camera always exceeding 0, so the camera never comes to a complete stop.)

Code:
var CamDist:Number = Math.sqrt(Math.abs((CamCurrX - (_root.character._x - (_root._width/2)))) + Math.abs((CamCurrY - (_root.character._x - (_root._width/2)))));
var CamAngle:Number = Math.atan2(Math.abs((CamCurrY - (_root.character._y - (_root._height/2)))),Math.abs((CamCurrX - (_root.character._x - (_root._width/2)))));
if(charSpeed > 10){
var CamSpeed:Number = charSpeed *.5;
}else{
var CamSpeed:Number = 5;
}
if(CamDist > CamSpeed){
var CamCurrY:Number = CamCurrY + (CamSpeed * Math.cos(CamAngle));
var CamCurrX:Number = CamCurrX + (CamSpeed * Math.sin(CamAngle));
}
_root._x = CamCurrX;
_root._y = CamCurrY;


Pretty simple, flexible code. Uses a tiny bit of basic trigonometry, but it shouldn't be anything too difficult to figure out. Just be sure to change the camera speed threshold to something reasonable given how fast your character is moving, and declare CamCurrY and CamCurrX, or you'll end up with a camera starting from 0,0 (I'm assuming that would be the default assigned value) frantically trying to reach the character. I think I might have used a few too many parenthesis somewhere, so you might get a glitch while compiling. I wanted to be absolutely sure it would follow the proper order of operations.

Hmm, I should probably save this code, it might come in handy in the future.

_________________
Image

Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper.

READ THIS: http://ipgd.freehostia.com/copypasta.html


Thu Apr 30, 2009 12:10 am
User avatar

Joined: Tue Oct 28, 2008 1:37 pm
Posts: 300
thanks you too i tryed all the codes and nothing was wrong with x2i but ye thanks :mrgreen:

_________________
Image
super smash bros blits(working title)-1% done
new flash game


Thu Apr 30, 2009 2:25 pm
Display posts from previous:  Sort by  
 [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.