3 Replies - 542 Views - Last Post: 22 January 2012 - 01:47 PM Rate Topic: -----

Topic Sponsor:

#1 mikex6989  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 97
  • Joined: 18-February 11

Actionscript 3.0 - VCAM Help

Posted 20 January 2012 - 08:17 PM

Hey guys... I'm trying to figure out how to make vcam follow my character. I got it somewhat working, by setting the vcam x and y to the player x and y on the first frame, but my character position is all over the place and the player doesn't do the same functionalities as it would without the cam. If anyone knows any solutions I would greatly appreciate it. Also, I would post the code, but I am not sure what I would post (whether it be the vcam code or my code). I'd be willing to send the file for help via dropbox. Let me know! Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Actionscript 3.0 - VCAM Help

#2 ButchDean  Icon User is offline

  • Pro Games Programmer
  • member icon


Reputation: 689
  • View blog
  • Posts: 2,504
  • Joined: 26-November 10

Re: Actionscript 3.0 - VCAM Help

Posted 20 January 2012 - 11:38 PM

Just post the code associated with your problem.
Was This Post Helpful? 0
  • +
  • -

#3 mikex6989  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 97
  • Joined: 18-February 11

Re: Actionscript 3.0 - VCAM Help

Posted 21 January 2012 - 10:58 PM

stop();

import flash.events.KeyboardEvent;
import flash.events.Event;

factBox.visible = false;

// Dna Buttons - added to stage

//pink
var DnaButton1:MovieClip = new dnaButton1();
floor.addChild(DnaButton1);
DnaButton1.x = 300.70;
DnaButton1.y = -151.40;
DnaButton1.width = 19.50;
DnaButton1.height = 19.55;

//orange
var DnaButton2:MovieClip = new dnaButton2();
floor.addChild(DnaButton2);
DnaButton2.x = -654.80;
DnaButton2.y = -280.85;
DnaButton2.width = 19.50;
DnaButton2.height = 19.55;

//blue
var DnaButton3:MovieClip = new dnaButton3();
floor.addChild(DnaButton3);
DnaButton3.x = -434.40;
DnaButton3.y = -326.20;
DnaButton3.width = 19.50;
DnaButton3.height = 19.55;

//teal
var DnaButton4:MovieClip = new dnaButton4();
floor.addChild(DnaButton4);
DnaButton4.x = -58.10;
DnaButton4.y = -352.35;
DnaButton4.width = 19.50;
DnaButton4.height = 19.55;

//light green
var DnaButton5:MovieClip = new dnaButton5();
floor.addChild(DnaButton5);
DnaButton5.x = -178.80;
DnaButton5.y = -332.80;
DnaButton5.width = 19.50;
DnaButton5.height = 19.55;

//black
var DnaButton6:MovieClip = new dnaButton6();
floor.addChild(DnaButton6);
DnaButton6.x = 174.50;
DnaButton6.y = -258.20;
DnaButton6.width = 19.50;
DnaButton6.height = 19.55;

//purple
var DnaButton7:MovieClip = new dnaButton7();
floor.addChild(DnaButton7);
DnaButton7.x = 853.80;
DnaButton7.y = -238.65;
DnaButton7.width = 19.50;
DnaButton7.height = 19.55;

//red
var DnaButton8:MovieClip = new dnaButton8();
floor.addChild(DnaButton8);
DnaButton8.x = 81.05;
DnaButton8.y = -284.25;
DnaButton8.width = 19.50;
DnaButton8.height = 19.55;

//yellow
var DnaButton10:MovieClip = new dnaButton10();
floor.addChild(DnaButton10);
DnaButton10.x = 734.95;
DnaButton10.y = -200;
DnaButton10.width = 19.50;
DnaButton10.height = 19.55;

var rightKeyIsDown:Boolean = false;
var leftKeyIsDown:Boolean = false;
var upKeyIsDown:Boolean = false;
var downKeyIsDown:Boolean = false;

var playerSpeed:Number = 7;
var gravity:Number = 1;
var yVelocity:Number = 0;
var canJump:Boolean = false;

var scoreCount:int = 0;

stage.addEventListener(KeyboardEvent.KEY_DOWN, PressAKey);
stage.addEventListener(KeyboardEvent.KEY_UP, ReleaseAKey);

//PressAKeyFunction here
function PressAKey(event:KeyboardEvent):void
{
	if(event.keyCode == Keyboard.RIGHT)
	{
		
	rightKeyIsDown = true;
	
	}
	if(event.keyCode == Keyboard.LEFT)
	{
		
	leftKeyIsDown = true;
	
	}
	if(event.keyCode == Keyboard.UP)
	{
		
	upKeyIsDown = true;
	
	}
	if(event.keyCode == Keyboard.DOWN)
	{
		
	downKeyIsDown = true;
	
	}
}


//ReleaseAKeyFunction here
function ReleaseAKey(event:KeyboardEvent):void
{
	if(event.keyCode == Keyboard.RIGHT)
	{
		
	rightKeyIsDown = false;
	
	}
	if(event.keyCode == Keyboard.LEFT)
	{
		
	leftKeyIsDown = false;
	
	}
	if(event.keyCode == Keyboard.UP)
	{
		
	upKeyIsDown = false;
	
	}
	if(event.keyCode == Keyboard.DOWN)
	{
		
	downKeyIsDown = false;
	
	}
}

player.addEventListener(Event.ENTER_FRAME, moveplayer);
function moveplayer(event:Event):void
{
	if (player.hitTestObject(die)) {
			gotoAndPlay(1, "Level 1");
			player.removeEventListener(Event.ENTER_FRAME, moveplayer);
			trace("die");
		}
	
	//red
	if (player.hitTestObject(DnaButton1)) {
		scoreCount = scoreCount + 500;
		factBox.visible = true;
		floor.removeChild(DnaButton1);
	}
	
		//orange
		if (player.hitTestObject(DnaButton2)) {
		scoreCount = scoreCount + 500;
		floor.removeChild(DnaButton2);
	}
	
		//blue
		if (player.hitTestObject(DnaButton3)) {
		scoreCount = scoreCount + 500;
		floor.removeChild(DnaButton3);
	}
		
		//teal
		if (player.hitTestObject(DnaButton4)) {
		scoreCount = scoreCount + 500;
		floor.removeChild(DnaButton4);
	}
	
	//light green
		if (player.hitTestObject(DnaButton5)) {
		scoreCount = scoreCount + 500;
		floor.removeChild(DnaButton5);
	}
	
	//black
		if (player.hitTestObject(DnaButton6)) {
		scoreCount = scoreCount + 500;
		floor.removeChild(DnaButton6);
	}
	
		//purple
		if (player.hitTestObject(DnaButton7)) {
		scoreCount = scoreCount + 500;
		floor.removeChild(DnaButton7);
	}
	
		//red
		if (player.hitTestObject(DnaButton8)) {
		scoreCount = scoreCount + 500;
		floor.removeChild(DnaButton8);
	}
	
		//yellow
		if (player.hitTestObject(DnaButton10)) {
		scoreCount = scoreCount + 500;
		floor.removeChild(DnaButton10);
	}
	
	
	if(rightKeyIsDown)
	{	
		floor.x -= 9;
		//player.x += playerSpeed;
		player.scaleX = .5;
		player.gotoAndStop(2);
		
	}
	if(leftKeyIsDown)
	{
		floor.x += 9;
		//player.x -= playerSpeed;
		player.scaleX = -.5;
		player.gotoAndStop(2);
		
	}
	if(upKeyIsDown && canJump)
	{
		yVelocity =- 15;
		canJump = false;
		player.gotoAndStop(3);
	}
	
	if(! rightKeyIsDown && ! leftKeyIsDown && ! upKeyIsDown) {
		player.gotoAndStop(1);
	}
	
	yVelocity += gravity;
	
	//if(!canJump)
	//yVelocity += gravity;
	
	
	if (! floor.hitTestPoint(player.x, player.y, true))
	{
		player.y+=yVelocity;
	}
	
	if (yVelocity > 20)
	{
		yVelocity = 20;
	}
	
	for (var i:int = 0; i<10; i++)
	{
		if (floor.hitTestPoint(player.x, player.y, true))
		{
			player.y --;
			yVelocity = 0;
			canJump = true;
		}
		
	}
	
		score.text = "Score: " + scoreCount;
		
	}


	
factBox.ok.addEventListener(MouseEvent.MOUSE_DOWN, leaveFactBox1);
function leaveFactBox1(e:MouseEvent): void
{
	factBox.visible = false;	
}
	
	

This post has been edited by mikex6989: 21 January 2012 - 10:59 PM

Was This Post Helpful? 0
  • +
  • -

#4 ButchDean  Icon User is offline

  • Pro Games Programmer
  • member icon


Reputation: 689
  • View blog
  • Posts: 2,504
  • Joined: 26-November 10

Re: Actionscript 3.0 - VCAM Help

Posted 22 January 2012 - 01:47 PM

It looks like (from a visual scan of your code) that you haven't coupled the motions of your camera with the motion of the object. I think some vector math would be helpful in that respect.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1