Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-02-2003, 10:09 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
?keeping the player from going on walls

I'm trying to find SOME way to keep the player from freezing (not being able to move) or going into the wall.

momentumx is how fast the player is moving toward the wall.

When the player hits the wall they are redirected into the other direction.

bounceloss is how much momentum is lost when the player is redirected off the wall.

--I'm also going to remove the freezeplayer in this script sooner or later.

NPC Code:

//Momentum (Ice) Script by Massokre
if (created){
friction = .005;
//how much the player slows down naturally, or speeds up naturally if you put it in negatives. Don't put it higher than accel unless you REALLY want to experiment.
momentumcap = 2;
//maximum speed
accel = .02;
//acceleration speed
bounceloss = 2;
//speed is divided by this when player hits walls, 1 for no bounce loss, cannot be 0. Division by 0=BAD.
setani cn_walk,;
this.momentumy = 0;
//original y momentum
this.momentumx = 0;
//original x momentum
freezeplayer .3;
this.ice = 0;
timeout = .05;
}

if (playerchats&&strequals(#c,ice off)){
this.ice = 0;
}

if (playerchats&&strequals(#c,ice on)){
this.ice = 1;
}

if (timeout){

if (this.ice = 1){

if (this.momentumx > friction){
this.momentumx -= friction;
}

if (this.momentumy > friction){
this.momentumy -= friction;
}

if (this.momentumx < -friction){
this.momentumx += friction;
}

if (this.momentumy < -friction){
this.momentumy += friction;
}

if (this.momentumy <= 0&&this.momentumy >= -friction){
this.momentumy = 0;
}

if (this.momentumy >= 0&&this.momentumy <= friction){
this.momentumy = 0;
}

if (this.momentumx <= 0&&this.momentumx >= -friction){
this.momentumx = 0;
}

if (this.momentumx >= 0&&this.momentumx <= friction){
this.momentumx = 0;
}

if (this.momentumx = 0&&this.momentumy = 0){
setani cn_idle,;
}

else{
setani cn_walk,;
}

if (keydown(0)&&!this.momentumy<-momentumcap){
playerdir = 0;
this.momentumy -= accel;
}

if (keydown(1)&&!this.momentumx<-momentumcap){
playerdir = 1;
this.momentumx -= accel;
}

if (keydown(2)&&!this.momentumy>momentumcap){
playerdir = 2;
this.momentumy += accel;
}

if (keydown(3)&&!this.momentumx>momentumcap){
playerdir = 3;
this.momentumx += accel;
}


if (onwall(playerx+.45,playery)||onwall(playerx,playe ry+3)||onwall(playerx,playery+1)||onwall(playerx+2 .5,playery)){

if (this.momentumy>=0){
this.momentumy=-abs(this.momentumy)/bounceloss;
}

if (this.momentumy<=0){
this.momentumy=abs(this.momentumy)/bounceloss;
}

if (this.momentumx>=0){
this.momentumx=-abs(this.momentumx)/bounceloss;
}

if (this.momentumx<=0){
this.momentumx=abs(this.momentumx)/bounceloss;
}

}
playerx += this.momentumx;
playery += this.momentumy;
freezeplayer .3;
}
timeout = .05;
}



Edit-- I don't care about vectors.
Reply With Quote
  #2  
Old 09-02-2003, 10:20 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
You know there's a difference between speed and momentum, right?
__________________
Reply With Quote
  #3  
Old 09-02-2003, 10:33 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
yes, but momentum=speed in this script.
Reply With Quote
  #4  
Old 09-02-2003, 10:51 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
They might have the same values in this case, but that doesn't make them the same thing.

Incidentally, increasing the magnitude of two components of a vector by a certain constant does not merely increase the composite vector's magnitude by the same amount. Worse than that, it also changes the direction of the vector. Just a heads up.

BTW: KSI-GS
__________________
Reply With Quote
  #5  
Old 09-02-2003, 10:55 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
so, are you saying don't try using vectors for this? I've completely forgotten vectors since the last time I used it. something about <x+,y+> or something.
Reply With Quote
  #6  
Old 09-02-2003, 11:09 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally posted by jake13jake
so, are you saying don't try using vectors for this? I've completely forgotten vectors since the last time I used it. something about <x+,y+> or something.
No idea what that is. A vector is just a combination of numbers that usually represents position or direction&magnitude. In this case you're using a vector to represent the player's speed (though you're inexplicably calling it momentum). However, when you decelerate the character you are not merely reducing his overall speed by the value of this.friction - instead you are reducing his speed by a variable amount and changing his direction too.
__________________
Reply With Quote
  #7  
Old 09-02-2003, 11:19 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally posted by Kaimetsu


No idea what that is. A vector is just a combination of numbers that usually represents position or direction&magnitude. In this case you're using a vector to represent the player's speed (though you're inexplicably calling it momentum). However, when you decelerate the character you are not merely reducing his overall speed by the value of this.friction - instead you are reducing his speed by a variable amount and changing his direction too.
lol, inexplicably? if you played with the script it might be explicable. I think I'm starting to understand what a vector is again, but I don't quite understand what it is in graal scripting.

I understand that I am changing the direction of the player. If I werent changing the direction he would be going through the wall (which it does sometimes anyways). I think I might have just thought of a solution, to the effect that I want. Maybe if I tested when the player was close to a wall and replaced momentum temporarily with the distance from the wall... wait... figures... how am i supposed to find the distance from the wall? I would try cutting momentum in half each time it doesn't detect but that most likely wouldn't give the desired effect... Why couldn't stefan have made this easier?
Reply With Quote
  #8  
Old 09-02-2003, 11:24 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally posted by jake13jake
lol, inexplicably? if you played with the script it might be explicable.
No amount of playing with code will change a fundamental physical fact.

Quote:
I understand that I am changing the direction of the player. If I werent changing the direction he would be going through the wall
You misunderstand. The code that is intended to slow the player also changes his direction of movement. I'm not talking about the parts where he bounces off walls, I'm talking merely about the section that applies friction.

Quote:
Why couldn't stefan have made this easier?
It's easy enough already, assuming you have the sense not to disregard an area of maths that holds the key to your success.

Oh, and non-prefixed variables are volatile. If you require a variable to retain its value between frames, prefix it with a 'this'.
__________________
Reply With Quote
  #9  
Old 09-02-2003, 11:34 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
You misunderstand. The code that is intended to slow the player also changes his direction of movement. I'm not talking about the parts where he bounces off walls, I'm talking merely about the section that applies friction.

if (this.momentumy <= 0&&this.momentumy >= -friction){
this.momentumy = 0;
}

if (this.momentumy >= 0&&this.momentumy <= friction){
this.momentumy = 0;
}

if (this.momentumx <= 0&&this.momentumx >= -friction){
this.momentumx = 0;
}

if (this.momentumx >= 0&&this.momentumx <= friction){
this.momentumx = 0;
}

I guess I do misunderstand. I thought that adding this would check it.
--Do you mean this is a bad way to check it?


Quote:
No amount of playing with code will change a fundamental physical fact.
I didn't mean playing with the code. I meant playing, as in being able to move a char across the screen with the arrow keys playing.


Edit-- It's a shame that I didn't make this to be an airplane script.. Then I wouldn't have to bother with player speed (haven't bothered with yet but will probably be a pain) and onwall.
Reply With Quote
  #10  
Old 09-02-2003, 11:39 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
From newfeatures2003-v3.txt:
Quote:
- onwall2(x,y,width,height) to test a rectangular area
--that is something that would be REMARKABLY helpful... maybe I should just play around with the script in 3.01 for now?
Reply With Quote
  #11  
Old 09-02-2003, 11:44 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally posted by jake13jake
I guess I do misunderstand. I thought that adding this would check it.
--Do you mean this is a bad way to check it?
In that code you are checking if the player has stopped. It is not what I am talking about, but it's indicative of the same mentality. If you treat the player's x and y velocities as separate concepts then you're likely to make mistakes such as the one I've pointed out. Want more? No problem.

1) Moving diagonally increases the player's speed more quickly than solely moving in any of the four main directions.
2) If the player moves diagonally, he/she can travel ~1.4 times faster than normal.

There are also other problems. The onwall check, for example, is inaccurate. The response to the detection of the wall is flawed too. Application of KSI-GS could fix it, but I guess you don't care about that any more than you care about vectors.

Quote:
I didn't mean playing with the code. I meant playing, as in being able to move a char across the screen with the arrow keys playing.
No amount of playing a computer game will change a fundamental physical fact.
__________________
Reply With Quote
  #12  
Old 09-02-2003, 12:16 PM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally posted by jake13jake
From newfeatures2003-v3.txt:


--that is something that would be REMARKABLY helpful... maybe I should just play around with the script in 3.01 for now?
sure but you loose the offline editor if you use v3.x
Reply With Quote
  #13  
Old 09-02-2003, 01:20 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
you can save it in v2 and then open v3... but it seems to have the same effect as the one I was using before.



Quote:
No amount of playing a computer game will change a fundamental physical fact.
to Kaimets: I named it momentum because the player's x and y coords will continue motion at that rate.

Quote:
1) Moving diagonally increases the player's speed more quickly than solely moving in any of the four main directions.
This isn't my problem

Quote:
The onwall check, for example, is inaccurate.
This IS my problem

Quote:
Application of KSI-GS could fix it, but I guess you don't care about that any more than you care about vectors.
It's not that I don't care, it's just that I don't know. I was told that I could use vectors on this script just to shorten it, which leads me to believe that it is also fine the way it is.

I am NOT very accustomed to making scripts as I believe that you probably are. I deny that I am a good scripter if anyone believes that I am. I am better with ideas than I am with putting them into effective scripts.
--Just ask Kat, he'll tell you that I'm bad at explaining ideas, too.
Reply With Quote
  #14  
Old 09-02-2003, 02:05 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally posted by jake13jake
to Kaimets: I named it momentum because the player's x and y coords will continue motion at that rate.
That's velocity. They're different.

Quote:

This isn't my problem

This IS my problem
They're both problems.

Quote:
It's not that I don't care, it's just that I don't know. I was told that I could use vectors on this script just to shorten it, which leads me to believe that it is also fine the way it is.
You're already using a vector, you just don't realise it.

Quote:
I am NOT very accustomed to making scripts as I believe that you probably are. I deny that I am a good scripter if anyone believes that I am. I am better with ideas than I am with putting them into effective scripts.
You don't need to be a good scripter to understand KSI-GS.
__________________
Reply With Quote
  #15  
Old 09-02-2003, 02:52 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
That's velocity. They're different.
retake physics.
Quote:
They're both problems.
maybe they are, but I'm only focusing on one.
Quote:
You're already using a vector, you just don't realise it.
what you say :P.
Quote:
You don't need to be a good scripter to understand KSI-GS.
First of all, what's KSI-GS?
Reply With Quote
  #16  
Old 09-02-2003, 03:20 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally posted by jake13jake
retake physics.
This from the kid who doesn't know what a vector is?

Quote:
maybe they are, but I'm only focusing on one.
Then you're a fool and not deserving of my help.

Quote:
First of all, what's KSI-GS?
http://forums.graal2001.com/forums/s...threadid=46557
__________________
Reply With Quote
  #17  
Old 09-02-2003, 03:33 PM
Soul-Blade Soul-Blade is offline
US Marine
Soul-Blade's Avatar
Join Date: Jul 2001
Location: Coeur d'Alene, ID
Posts: 945
Soul-Blade is an unknown quantity at this point
Send a message via AIM to Soul-Blade
Listen to Kai and his vector talk, then do research. In addition to learning about vectors, you can learn alot of other useful stuff. It took me about a year to understand "Kai-Talk", because it took me a year to think about research on all scripts before attempting them to get insight from programmers, and to research on maths I know I will need in scripts, which I do not already know.

Don't make the same mistake =P.
Reply With Quote
  #18  
Old 09-03-2003, 12:41 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
Don't get mad at Kai, he's telling the truth, you're just not understanding (which is pretty much understandable). Let me clarify for you, you have two major problems with the code;

1. there are quite a few more lines than there needs to be, meaning you can break down all those separate if checks for each direction into a for loop, but I'll let you figure how to fix that on your own

2. your wall check is highly innacurate, it only checks immediately, well actually I have no idea where you were going with those numbers... but it would greatly improve upon your script to do some dynamic checking, meaning you should check the area the player will be moving to before you actually send him/her there using your "momentum" variables and playerx/y

oh and vecx/vecy are your friends when using for loops to compile directional scripts
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #19  
Old 09-06-2003, 01:29 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
2. your wall check is highly innacurate, it only checks immediately, well actually I have no idea where you were going with those numbers... but it would greatly improve upon your script to do some dynamic checking, meaning you should check the area the player will be moving to before you actually send him/her there using your "momentum" variables and playerx/y
FINALLY someone answers my question.

I don't like kai because he was straying off of my question. Something that I should say to kai: I know about the other problems it's just that i'm dealing with them one at a time.
Reply With Quote
  #20  
Old 09-06-2003, 03:43 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Yes, any help that doesn't follow your exact specifications is evil and venemous.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.