Be a Supporter!

Complete Character Movement

  • 399 Views
  • 9 Replies
New Topic Respond to this Topic
Eviladrianin
Eviladrianin
  • Member since: Sep. 27, 2009
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Complete Character Movement 2009-12-20 04:11:49 Reply

Hey! I need some help for my character movement becaause it's very simple movement and i want more like friction, walk and run, etc.
This is the code, i hope answers.

onClipEvent (load) {
	var grav:Number = 0;
	// gravity
	var speed:Number = 10;
	// how fast you walk
	var jumpHeight:Number = 15;
	// how high you jump
	var slow:Number = .7;
	// sets water falling speed
	var slowspd:Number = speed/1.5;
	// sets water walking speed
	var setspeed:Number = speed;
	var scale:Number = _xscale;
	var ex:Number = 5;
	this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
	grav++;
	_y += grav;
	while (_root.ground.hitTest(_x, _y, true)) {
		_y--;
		grav = 0;
	}
	if (_root.water.hitTest(_x, _y, true)) {
		if (grav>0) {
			grav *= slow;
		}
		speed = slowspd;
	} else {
		speed = setspeed;
	}
	if (Key.isDown(68)) {
		_x += speed;
		_xscale = scale;
		if (_root.ground.hitTest(_x, _y+1, true)) {
			this.gotoAndStop(1);
		} else {
			this.gotoAndStop(2);
		}
	} else if (Key.isDown(65)) {
		_x -= speed;
		_xscale = -scale;
		if (_root.ground.hitTest(_x, _y+1, true)) {
			this.gotoAndStop(1);
		} else {
			this.gotoAndStop(2);
		}
	} else {
		if (_root.ground.hitTest(_x, _y+1, true) && !Key.isDown(79) && !Key.isDown(73)) {
			this.gotoAndStop(3);
		}
	}
	if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(73)) {
		this.gotoAndStop(5);
	}
	if (Key.isDown(73) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(79)) {
		this.gotoAndStop(4);
	}
	if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
		grav = -jumpHeight;
		_y -= 4;
		this.gotoAndStop(2);
	}
	if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/6), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-_height, true)) {
		_x -= speed;
	}
	if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/6), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-_height, true)) {
		_x += speed;
	}
	if (_root.ground.hitTest(_x, _y-_height-15, true)) {
		grav = 1;
	}
}
LostVoices
LostVoices
  • Member since: Mar. 9, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Complete Character Movement 2009-12-20 04:13:38 Reply

i'm not understanding?

are you wanting us to rewrite your code to implement friction?


awww

Montycarlo
Montycarlo
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Complete Character Movement 2009-12-20 04:19:39 Reply

At 12/20/09 04:13 AM, LostVoices wrote: are you wanting us to rewrite your code to implement friction?

This isn't even his code. I think this is Pyromaniac's older ones.

No. We're not going to do this for you, why should we? You haven't even bothered to make the basic code yourself, you've merely used copypasta. Instead, we'll help you how you should have helped yourself: "Friction is the decline of velocity, so I need a variable that controls the velocity of the object, and some statements that add to the velocity and decrease it when the movement keys are being held down and unpressed. I'll also need a cap for the velocity - or else the object will able to go so fast no-one will see it!"


Although practicality beats purity.
Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.

LostVoices
LostVoices
  • Member since: Mar. 9, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Complete Character Movement 2009-12-20 04:23:40 Reply

At 12/20/09 04:19 AM, Montycarlo wrote:
At 12/20/09 04:13 AM, LostVoices wrote: are you wanting us to rewrite your code to implement friction?
This isn't even his code. I think this is Pyromaniac's older ones.

i'm going to agree with you here, if it was his code and he could figure out Gravity and Walking in water speed there should be no problem with Friction / Acceleration


awww

Eviladrianin
Eviladrianin
  • Member since: Sep. 27, 2009
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Complete Character Movement 2009-12-20 06:13:49 Reply

Well, i just need an explanation for the friction/aceleration code.

HonterGames
HonterGames
  • Member since: Jun. 18, 2009
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Complete Character Movement 2009-12-20 06:22:24 Reply

Good job making a whole other thread instead of a response BTW

Anyways try and learn the code urself OP, its not really hard, and nobodys going to write out the whole code for you anyway. Try and learn from tutorials rather than just copying the code.


BBS Signature
Montycarlo
Montycarlo
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Complete Character Movement 2009-12-20 06:25:29 Reply

At 12/20/09 06:13 AM, Eviladrianin wrote: Well, i just need an explanation for the friction/aceleration code.

I gave you one. Clearly you don't read or put in any effort.


Although practicality beats purity.
Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.

Eviladrianin
Eviladrianin
  • Member since: Sep. 27, 2009
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Complete Character Movement 2009-12-20 06:54:34 Reply

Oh yeah! Finally i understand the friction!!
Thanks to all for your comments

LostVoices
LostVoices
  • Member since: Mar. 9, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Complete Character Movement 2009-12-20 06:54:37 Reply

At 12/20/09 06:13 AM, Eviladrianin wrote: Well, i just need an explanation for the friction/aceleration code.

Hey there! :)

so while you were sitting here pressing your browsers refresh button anxiously awaiting for someone to give you the code i thought to myself.. HEY.. wait why don't i go and research this for his, learn the code, then come back and teach him how to complete it :D

don't get me wrong i understand how much time it takes out of someone's busy schedule to press the refresh button and i commend you for it.

but while doing all this i did stumble across this helpful little link.

i hope this helps


awww

LostVoices
LostVoices
  • Member since: Mar. 9, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Complete Character Movement 2009-12-20 06:55:38 Reply

http://tinyurl.com/ygpznal


awww