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 07-09-2013, 09:08 PM
brokk brokk is offline
Registered User
Join Date: May 2012
Posts: 84
brokk is on a distinguished road
Looking for a solution

Hello. I need some help. I have a showImg shadow and I want it to follow player and it does. But the problem I am running into is when the player jumps, the shadow also follows the player's y value so there is no sense in depth when jumping. (Keep in mind player can move in all 4 directions just like default movement.)

So I come to you forums in need of help.
Some information on the jump action:
The player's y value goes -0.5 when jumps for a time of (0.5)
The player's y value goes +0.5 when falling for a time of (0.5)
So the jump is (1) total in time.
The Jump and Fall are just ran through a looping script.

Jumping works perfect, the shadow just doesn't like to.



I've tried:
1. Keeping the y value at one point once the player has left the ground.
Problem: When you move up or down while jumping, the shadow
jumps when you land.

2. A bunch of sleeps();
Problem: Glitchy

3. A butt load of scheduleEvents()
Problem: Even more glitchy.

PHP Code:
//#CLIENTSIDE
function onCreated(){
 
setTimer(0.05);
 }
 
function 
onTimeOut(){
 
setTimer(0.05);
//SHADOW
 
if (player.canjump true){
//THIS IS WHERE PLAYER IS ON GROUND. WORKS FINE
  
showImg(20"shadow.png"player.x+0.5player.y+1.5);
  
changeImgVis(201);
  
findImg(20).layer 0;
 }
//PLAYER IS IN AIR HERE, BUT TOOK OUT WHAT I HAD
 
if (player.canjump false){
 }
}



function 
onKeyPressed(codekey){
 if (
key == "s"){  //'s' JUMPS. THE ACTION IS DONE ON ANOTHER SCRIPT
  
if (canjump true){
  
//I DONT KNOW WHAT TO DO HERE. I TRIED A LOT AND FAIL EVERYTIME
    
showImg(20"shadow.png"player.x+0.5player.y+1.5);
    
changeImgVis(201);
    
findImg(20).layer 0;
    
//DELETED IDEA
    
}
   }
  } 
__________________
No matter how much I hate graal, I'm always coming back.

smh
Reply With Quote
  #2  
Old 07-09-2013, 09:43 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
The player's z property changes when jumping (I believe) so try changing the z property of that image object to match the player's z property.
Reply With Quote
  #3  
Old 07-09-2013, 09:50 PM
brokk brokk is offline
Registered User
Join Date: May 2012
Posts: 84
brokk is on a distinguished road
Quote:
Originally Posted by Emera View Post
The player's z property changes when jumping (I believe) so try changing the z property of that image object to match the player's z property.
I've never messed with any Z values... You may have to go more in depth with me... I'm sorry
__________________
No matter how much I hate graal, I'm always coming back.

smh
Reply With Quote
  #4  
Old 07-09-2013, 09:53 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Take a look at the changeimgzoom(id,factor) function.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #5  
Old 07-09-2013, 11:06 PM
brokk brokk is offline
Registered User
Join Date: May 2012
Posts: 84
brokk is on a distinguished road
Quote:
Originally Posted by BlueMelon View Post
Take a look at the changeimgzoom(id,factor) function.
Though that will make the shadow smaller, it will not change the distance from the player and the shadow when jumping.
__________________
No matter how much I hate graal, I'm always coming back.

smh
Reply With Quote
  #6  
Old 07-09-2013, 11:16 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Quote:
Originally Posted by brokk View Post
Though that will make the shadow smaller, it will not change the distance from the player and the shadow when jumping.
Ah ok then what you want to mess around with is the player.z variable. It's exactly what you want I think.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #7  
Old 07-10-2013, 12:15 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
first off: why are you using that kind of shadow instead of the default one in the ganis?
seccond thing: watch your if() statements
__________________
MEEP!
Reply With Quote
  #8  
Old 07-10-2013, 12:59 AM
brokk brokk is offline
Registered User
Join Date: May 2012
Posts: 84
brokk is on a distinguished road
Quote:
Originally Posted by callimuc View Post
first off: why are you using that kind of shadow instead of the default one in the ganis?
seccond thing: watch your if() statements
Because I need the shadow to display a "sense" of depth. If the shadow stayed with the player, it would just look like the player is rolling up and down..
__________________
No matter how much I hate graal, I'm always coming back.

smh
Reply With Quote
  #9  
Old 07-10-2013, 01:00 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by callimuc View Post
seccond thing: watch your if() statements
To clarify, he's talking about stuff like this:

PHP Code:
 if (player.canjump true){ 
A single equals sign is used for assignment. A double equals sign is for comparison. GS2 tolerates misuse to some degree (it shouldn't...) which is why your script still works, but you should instead do:

PHP Code:
 if (player.canjump == true){ 
__________________
Reply With Quote
  #10  
Old 07-10-2013, 02:18 AM
brokk brokk is offline
Registered User
Join Date: May 2012
Posts: 84
brokk is on a distinguished road
Quote:
Originally Posted by cbk1994 View Post
To clarify, he's talking about stuff like this:

PHP Code:
 if (player.canjump true){ 
A single equals sign is used for assignment. A double equals sign is for comparison. GS2 tolerates misuse to some degree (it shouldn't...) which is why your script still works, but you should instead do:

PHP Code:
 if (player.canjump == true){ 
Yeah I fixed the 'if' statements. But I still can't find a solution to my problem
__________________
No matter how much I hate graal, I'm always coming back.

smh
Reply With Quote
  #11  
Old 07-10-2013, 11:37 AM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Have you tried using the player.z variable for your jump?
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #12  
Old 07-10-2013, 01:45 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
This is something that could work. Not 100% sure but I can't see something wrong


PHP Code:
//#CLIENTSIDE

const JUMP_HEIGHT 1//Player can jump one tile high

function onKeyPressed(codekey) {
    
//Won't change the player.canJump as you could keep it as a check
    //If the player could jump in theory for other scripts
  
if (key == "s" && player.canJump == true && player.== 0) {

      
//Create the shadow image
    
showImg(20"shadow.png"player.x+0.5player.y+1.5);
    
changeImgVis(201);
    
findImg(20).layer 0;
      
      
//I rathered to make it into one for() loop and have if statements
      //Inside of it instead of creating 2 loops, probably just a personal
      //Preference
    
for (temp.0temp.JUMP_HEIGHT*2temp.+= 0.05) {

        
//Since i took the JUMP_HEIGHT times 2, I can create such a check
      
if (temp.JUMP_HEIGHT) {
        
player.+= 0.05//Move the player up
      
}
      else {
        
player.-= 0.05//Move the player down
      
}
    }

      
//failsafe reset the player.z
    
player.0;

      
//hide the shadow as you will probably move back to the original one
    
hideImg(20);
  }

__________________
MEEP!
Reply With Quote
  #13  
Old 07-10-2013, 04:36 PM
brokk brokk is offline
Registered User
Join Date: May 2012
Posts: 84
brokk is on a distinguished road
Quote:
Originally Posted by callimuc View Post
This is something that could work. Not 100% sure but I can't see something wrong


PHP Code:
//#CLIENTSIDE

const JUMP_HEIGHT 1//Player can jump one tile high

function onKeyPressed(codekey) {
    
//Won't change the player.canJump as you could keep it as a check
    //If the player could jump in theory for other scripts
  
if (key == "s" && player.canJump == true && player.== 0) {

      
//Create the shadow image
    
showImg(20"shadow.png"player.x+0.5player.y+1.5);
    
changeImgVis(201);
    
findImg(20).layer 0;
      
      
//I rathered to make it into one for() loop and have if statements
      //Inside of it instead of creating 2 loops, probably just a personal
      //Preference
    
for (temp.0temp.JUMP_HEIGHT*2temp.+= 0.05) {

        
//Since i took the JUMP_HEIGHT times 2, I can create such a check
      
if (temp.JUMP_HEIGHT) {
        
player.+= 0.05//Move the player up
      
}
      else {
        
player.-= 0.05//Move the player down
      
}
    }

      
//failsafe reset the player.z
    
player.0;

      
//hide the shadow as you will probably move back to the original one
    
hideImg(20);
  }

I had just read read this this morning but I figured it out last night! thanks though!

I just simply change the z value of the player and the shadow stays at (player.x), and (player.y-player.z)

Works like a charm. I never knew about the z factor til yesterday so I would like to thank you graal forums for making life a lot easier on me lol
__________________
No matter how much I hate graal, I'm always coming back.

smh
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 09:13 AM.


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