Be a Supporter!

platform game help

  • 187 Views
  • 4 Replies
New Topic Respond to this Topic
rinoo
rinoo
  • Member since: Aug. 17, 2009
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
platform game help 2009-09-28 18:12:26 Reply

----------------------------------------
----------------------------------------

I am making a platform game in AS2 for school and everything works, but the rotation of the character to the ground.The rotation works by two points (dots) on the character that tell when they are hitting the ground. Does anyone know how to make it work so that the character rotates to the ground

Code:
onClipEvent (load) {
speed = 4;
jump = 0;
jumpheight = 9;
gravity = 0.5;
scale = _xscale;
wid = _width/2;
heig = _height/2;
//when the character moves his feet will play the animation, but when the movement stops, the feet reset to a rest position
}
onClipEvent (enterFrame) {
_y -= jump;
jump -= gravity;
if (Key.isDown(65)) {
_x -= speed;
_xscale = -scale;
}
if (Key.isDown(68)) {
_x += speed;
_xscale = +scale;
}
while (_root.ground.hitTest(_x, _y+heig, true)) {
_y--;
jump = -5;
inair = false;
if (inair == false && Key.isDown(87)) {
jump = jumpheight;
inair = true;
}
}
}
onClipEvent (enterframe) {
if (_root.ground.hitTest(_root.player["righ tpoint"])){
if (_root.ground.hitTest(_root.player["left point"])){
_root.player._rotation =0;
}else{
if (_root.ground.hitTest(_root.player["righ tpoint"])){
_root.player._rotation -=1;
}else{
if (_root.ground.hitTest(_root.player["left point"])){
_root.player._rotation +=1;
}
}
}
}
}

iluvAS
iluvAS
  • Member since: Nov. 18, 2007
  • Offline.
Forum Stats
Member
Level 08
Game Developer
Response to platform game help 2009-09-29 01:04:01 Reply

whenever you have coordinates and you nid rotation or when u have rotation and u nid coordinates..... its all about trigo my friend. Ok so for this to work my way... u nid to have to make sure

Your main character's registration point is set to centre

now lets have a trigo recap Toa Cah Soh
dats how i memorise em

tan(angle)=opposite/adjacent
cos(angle)=adjacent/hypotenuse
sin(angle)=opposite/hypotenuse

I hope u noe how this works cuz im lazy to explain those right angle triangle crapz. So erm now, i hope u mean 2 points as in one point is in contact with the floor on the right most side of the character an another point in contact with the floor on the left most side of the character. with having the registration point perfectly in between them (If u have a straight floor and not a curved one)

now all u nid to do is find the distance between the character's registration point and the external point coordinate. Now remember. if u are facing...

the right>>> u will take the external point on the right>>> and the registration point
the left>>> u will take the external point on the left>>> and the registration point

1st find the _x difference which is adjacent
2nd find the _y difference which is adjacent
3rd calculate angle

//in these examples i take it that u are facing the right and ur main char instance name is mc
adjacent=mc._x-rightpoint._x
opposite=mc._y-rightpoint._y
//note that AS calculates trig in radians and rotation is set using degrees
mc.rotation=Math.atan2(opposite,adjacent)*180/Math.PI

so erm yeah dats the basic of doing the rotation shit... hope this helps


BBS Signature
flailthefox
flailthefox
  • Member since: Aug. 30, 2007
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to platform game help 2009-09-29 02:49:53 Reply

At 9/28/09 06:12 PM, rinoo wrote:

:Does anyone know how to make it work so that the character rotates to the ground

This sounds simple.

Basically, you want something along the line of:

onClipEvent (enterframe) {
if (_root.ground.hitTest, true) && (Key.isDown(Key.RIGHT)) {
this._rotation +=3
}

And that's just for when pressing right.
Now, please please PLEASE DO NOT COPY/PASTE THIS. I just typed it from scratch, and may not be accurate or correct. It's just along the lines of that. I would replace ground wiht the instance name of the ground you have, and Key.RIGHT with whatever you press to go right, D ect.

this SHOULD work, but as i said, Don't copy/paste! Read it yourself and try to understand it.


Destroyed.

Innermike
Innermike
  • Member since: Sep. 11, 2009
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to platform game help 2009-09-29 11:49:59 Reply

At 9/29/09 02:49 AM, flailthefox wrote: onClipEvent (enterframe) {
if (_root.ground.hitTest, true) && (Key.isDown(Key.RIGHT)) {
this._rotation +=3
}
this SHOULD work

If the OP is talking about making the char turn when on a slope:

No it shouldnt first of you should refrain from OCE but in this case the rotation code should be in the floor NOT the main guy or else it would be a pain to do multiple floors.
_rotation = 3 directly set the rotation += makes it keep increasing
also you should use a WHILE statement instead of an IF statement and cut out the Key.isDown part all together or it will look wierd in fact :

onClipEvent (enterframe) {
if (this.hitTest(_root.guy)) {
_root.guy._rotation = 3 (or -3 for the other direction
}}

if hes talking about just making the guy rotate slightly when he goes faster :
i cant be fulped to type any more , that effect looks noobish any way seriously :P


nobody

Treerung
Treerung
  • Member since: Apr. 18, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to platform game help 2009-09-29 12:46:48 Reply

At 9/29/09 11:49 AM, hdxmike wrote: if hes talking about just making the guy rotate slightly when he goes faster :
i cant be fulped to type any more , that effect looks noobish any way seriously :P

Not to derail this thread, but what the hell does "fulped" mean?


:'(

BBS Signature