its nearly done i figured out the problem and im fixing it now
Slope Detection
(160 posts) (31 voices)-
Posted 4 years ago #
-
here i will show you all y it isn't working hopefully one of you can help me cuz i cant think at the moment
one of the balls goes to far on the big slopes and so it screws up the rotation
Posted 4 years ago # -
I think that's the same technique I use...
Do you calculate the angle between the 2 balls and rotate the line according to that?
I'm still trying to write a code that the 2 balls stay on the same distance towards eachother, that should fix some problems.Not in cruelty
Not in wrath
the Reaper came today.An Angel visited
this gray path
And took the cube away.Posted 4 years ago # -
Nyubis, you're figuring out a constant distance script?
Look here, there's a bit on constance distance: http://www.emanueleferonato.com/2007/08/26/creation-of-a-ragdoll-with-flash-part-2-constraints/
Also, I'm currently in the process of fine-tuning my slope detection
Posted 4 years ago # -
thanks for the link but i am still having problems with it not stuffing up when it goes at an angle higher than 90 degrees
Posted 4 years ago # -
Hrm, maybe you could send the .fla to me, I could see if I could work something out?
Posted 4 years ago # -
i just posted 4 no reason! mwahahaha!
i hate fcp6Posted 4 years ago # -
Posted 4 years ago #
-
Niall said:
I did very much like the example in the kirupa thread in the author's post that he was troubled with, it used slope detection but unfortunately he provided no source, so I guess I won't find out.
I say:
What thread?? Link?? I am doing the same thing on KF and need some help
Posted 4 years ago # -
what?i just posted 4 no reason! mwahahaha!
videoguy that was like 9 months ago!i hate fcp6Posted 4 years ago # -
1. create a rectangle with a curved in top (large)
2. create a square (small)
3. convert to movie clips- give instance names: rectangle = slope, square = player
4. set the square's registration to middle bottom
5. apply this code to first frame on root level:player.onEnterFrame = function() { back = player._y; front = player._y; center = player._y; while (slope.hitTest(player._x-20, back, true)) { back -= 1; } while (!slope.hitTest(player._x-20, back-1, true)) { back += 1; } while (slope.hitTest(player._x+20, front, true)) { front -= 1; } while (!slope.hitTest(player._x+20, front+1, true)) { front += 1; } while (slope.hitTest(player._x, center, true)) { center -= 1; } while (!slope.hitTest(player._x, center+1, true)) { center += 1; } player._y = center; player._rotation = Math.atan2(front-back, 40)*180/Math.PI; if (player._x<500) { if (Key.isDown(Key.RIGHT)) { player._x += 3; } } if (player._x>0) { if (Key.isDown(Key.LEFT)) { player._x -= 3; } } };yoPosted 4 years ago # -
Anyone have this code, or another that works, in AS3?
pi=3.141592653589793238462643383279502884197169399375195820974944592307816406Posted 3 years ago # -
It's pretty easy to port it to AS3. Just remove the underscores and put it in an event listener function.
Just got back on the internet after losing my access for a week. Read more on Random Discussion.Posted 3 years ago # -
I need to learn AS3.
@Komputer: There is a good tutorial somewhere on the Newgrounds BBS.
Posted 3 years ago # -
That's where I learned it. It's a great tutorial.
Just got back on the internet after losing my access for a week. Read more on Random Discussion.Posted 3 years ago # -
Thanks! It works, but it's a bit jerky. Here's my code:
var r:Boolean = false;
var l:Boolean = false;
var jumping:Number = 0;
var jumpingd:Boolean = false;
var falling:Boolean = false;
var walkSpeed:Number = 3;
var jumpSpeed:Number = 10;
var fallSpeed:Number = 0;
var xspeed:Number = 1
var yspeed:Number = 0;
var gravity:Number = .5;
var dir:Number = 1;ground.visible = false;
stage.addEventListener(Event.ENTER_FRAME, movement1);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keysDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keysUp);function keysDown(event:KeyboardEvent) {
if (event.keyCode==Keyboard.SPACE) {
jumpingd = true;
}
if (event.keyCode==Keyboard.RIGHT) {
r=true;
}
if (event.keyCode==Keyboard.LEFT) {
l=true;
}
}function keysUp(event:KeyboardEvent) {
if (event.keyCode==Keyboard.SPACE) {
jumpingd = false;
}
if (event.keyCode==Keyboard.RIGHT) {
r=false;
}
if (event.keyCode==Keyboard.LEFT) {
l=false;
}
}function movement1(event:Event) {
if((jumpingd==true) && (!jumping)) {
yspeed = -12;
jumping = 1;
}
yspeed += gravity;
while(ground.hitTestPoint(char.x, char.y + char.height/2, true)) {
char.y--;
yspeed = 0;
jumping = 0;
}
if ((!ground.hitTestPoint(char.x, char.y+char.height/2+1, true)) || (yspeed<0)) {
char.y += yspeed;
} else {
yspeed = 0;
jumping = 0;
}
if (r==true) {
char.x+=walkSpeed;
dir=1;
}
if (l==true) {
char.x-=walkSpeed;
dir=-1;
}
var back:Number = char.y;
var front:Number = char.y;
var center:Number = char.y;
while (ground.hitTestPoint(char.x-20, back, true)) {
back -= 1;
}
while (!ground.hitTestPoint(char.x-20, back-1, true)) {
back += 1;
}
while (ground.hitTestPoint(char.x+20, front, true)) {
front -= 1;
}
while (!ground.hitTestPoint(char.x+20, front+1, true)) {
front += 1;
}
//while (slope.hitTest(player._x, center, true)) {
//center -= 1;
//}
//while (!slope.hitTest(player._x, center+1, true)) {
//center += 1;
//}
//player._y = center;
char.rotation = Math.atan2(front-back, 40)*180/Math.PI;}
Do you know how it could get less jerky, or just how to make the char jump in the angle that he's at?
EDIT: To jump at the angle, I think you'd need something like:
char.y += Math.sin(char.rotation * Math.PI/180) * yspeed;
char.x += Math.cos(char.rotation * Math.PI/180) * walkSpeed;But, I don't know where it would go...
Any help?
pi=3.141592653589793238462643383279502884197169399375195820974944592307816406Posted 3 years ago # -
Oh, you mean this post?
http://www.newgrounds.com/bbs/topic/781155
I found that, but I still couldn't convert it to as3. Here's the code (It's inside the character):
onClipEvent (load) {
this.dir = 1;
function updateBB () {
while (!_root.ground.hitTest (_root.bb._x, _root.bb._y, true)) {
_root.bb._y++;
}
while (_root.ground.hitTest (_root.bb._x, _root.bb._y, true)) {
_root.bb._y--;
}
}
}
onClipEvent (enterFrame) {
if (Key.isDown (Key.RIGHT)) {
this._x += 10;
this.dir = 1;
}
if (Key.isDown (Key.LEFT)) {
this._x -= 10;
this.dir = -1;
}
while (!_root.ground.hitTest (this._x, this._y, true)) {
this._y += 5;
}
while (_root.ground.hitTest (this._x, this._y, true)) {
this._y--;
}
_root.bb._x = this._x + (20 * this.dir);
_root.bb._y = this._y;
updateBB ();
rot1 = Math.atan2 (_root.bb._y - this._y, _root.bb._x - this._x);
this._rotation = rot1 * 180 / Math.PI;
if (this.dir == -1) {
this._rotation += 180;
}
updateBB ();
}I couldn't port it to as3, though... Can any of you?
pi=3.141592653589793238462643383279502884197169399375195820974944592307816406Posted 3 years ago # -
Why can't you? If you know AS3 it shouldn't be that difficult.
Just got back on the internet after losing my access for a week. Read more on Random Discussion.Posted 3 years ago # -
nice guys! and if you want to get a smoother rotation changelization
instead of just saying this._rotation=(wanted rotation)
dovariable1=(wanted rotation)-this._rotation;
this._rotation+=1/5*variable1;The only reason I don't have a Nobel Prize is because I'm too much of a genius for the common mind to grasp.Posted 3 years ago # -
nice guys! and if you want to get a smoother rotation changelization
instead of just saying this._rotation=(wanted rotation)
do
variable1=(wanted rotation)-this._rotation;
this._rotation+=1/5*variable1;example:
http://www.truploader.com/view/396206
(spoof of fpa, its called, the Fancy Shorts Adventure)
p.s. i'll work on a code for more than 90 degree rotation.
The only reason I don't have a Nobel Prize is because I'm too much of a genius for the common mind to grasp.Posted 3 years ago #
Reply »
You must log in to post.
