Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (monarch), 1,259 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Have trouble learning to make player entity move #237708
11/21/08 18:18
11/21/08 18:18
Joined: Nov 2008
Posts: 24
Nevada, USA
Kevinper Offline OP
Newbie
Kevinper  Offline OP
Newbie

Joined: Nov 2008
Posts: 24
Nevada, USA
I have gone through many tutorials. Most of the older tutorials do not work as the syntax has change and keywords have been replaced.

I have a spaceship entity and I want it to be the player. I need to learn how to make it move forward, left, right, etc.

Can anyone help?

Thanks,

Kevin


Kevin
Re: Have trouble learning to make player entity move [Re: Kevinper] #237709
11/21/08 18:20
11/21/08 18:20
Joined: Aug 2003
Posts: 7,439
Red Dwarf
Michael_Schwarz Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,439
Red Dwarf


"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
Re: Have trouble learning to make player entity move [Re: Michael_Schwarz] #237720
11/21/08 18:53
11/21/08 18:53
Joined: Nov 2008
Posts: 24
Nevada, USA
Kevinper Offline OP
Newbie
Kevinper  Offline OP
Newbie

Joined: Nov 2008
Posts: 24
Nevada, USA
Thank you. I will "chew on this" for a while.


Kevin
Re: Have trouble learning to make player entity move [Re: Kevinper] #237734
11/21/08 20:27
11/21/08 20:27
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
Essentially, you want to update the player's x,y,z according to key strokes and allow it to move with its own orientation rather than with world coordinates.

Code:
VECTOR speed;

action moveMe()
{
  while(1)
  {
    my.pan += 5 * (key_a - key_d) * time_step;
    speed.x = 5 * (key_w - key_s) * time_step;
    c_move(my,speed,nullvector,IGNORE_PASSABLE | GLIDE);
    wait(1);
  }
}


Q&D movement code, just to show you the basics.

This code allows the player to move forward or backwards and turn, no gravity or strafing (gravity would be a negative z component in the absolute distance vector and strafing would use the y component of the speed vector).

The way it works is this: Key_w and key_s equal 1 or 0 if pressed or not, so speed.x is:
If key_w and not key_s:
5 * (1 - 0) * time_step = 5 * 1 * time_step = 5 * time_step
If key_s and not key_w:
5 * (0 - 1) * time_step = 5 * -1 * time_step = -5 * time_step
If neither:
5 * (0 - 0) * time_step = 5 * 0 * time_step = 0 * time_step = 0
If both:
5 * (1 - 1) * time_step = 5 * 0 * time_step = 0 * time_step = 0

We add in time_step so the speed stays the same, even if the frame rate changes.

The my.pan calculation works the same way.

We stick this vector in the relative distance parameter of c_move so it moves along its origin's orientation and not the world's orientation (otherwise we'd go forward, facing sideways). We also want c_move to ignore_passable and glide. c_move also gives us collision detection. In contrast, directly manipulating the objects .x, .y, and .z values does not give us collision.

Movement gets more complicated than this if you want to add more realism. Friction, speed changing on slopes, gravity, etc, but I just wanted to show the basic movement.

EDIT: The link in my sig goes to my programming blog, my most recent post has the entire action for my script. While it is unfinished and has a few problems yet, you can take a look at it and perhaps learn from it. It is Lite-C.

Last edited by heinekenbottle; 11/21/08 20:33.

I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: Have trouble learning to make player entity move [Re: heinekenbottle] #237752
11/21/08 23:50
11/21/08 23:50
Joined: Nov 2008
Posts: 24
Nevada, USA
Kevinper Offline OP
Newbie
Kevinper  Offline OP
Newbie

Joined: Nov 2008
Posts: 24
Nevada, USA
That's what I'm looking for is the basics. But how do I assign my entity to use the script? And do I put in in the Lite-c script or the wdl file?


Kevin
Re: Have trouble learning to make player entity move [Re: Kevinper] #237762
11/22/08 03:12
11/22/08 03:12
Joined: May 2006
Posts: 53
Puerto Rico
monchito Offline
Junior Member
monchito  Offline
Junior Member

Joined: May 2006
Posts: 53
Puerto Rico
Hi
i recommend use the C-Lite workshop as starting guide. The manual is helpful with code too. Start learning the use of SED(script editor) and the WED.
small code using SED assuming there is a model named 'myplayer.mdl'
http://server.conitec.net/down/litec.zip
Code:
[/code]

function act_player();

function main()
{
   fps_max = 50;
// load your level
   level_load (NULL);
   wait(5);
 // load the (player entity, assign position, assign default function) 
   ent_create ("myplayer.mdl", vector(0,0,0), act_player);
}

function act_player()
{
  var speed = 5;
  var rotation_speed = 3;
  my.scale_x = .5;  // change model size if necesary
  my.scale_y = .5;
  my.scale_z = .5;

  player = my;
	
  while(1)      
  {
     //update camera position relative to the model position
     camera.x = player.x;
     camera.y = player.y;
     camera.z = player.z + 5; // 5 units above the model origin
     camera.pan = player.pan; // set camera same pan as model
     camera.tilt = player.tilt;

     move_mode = IGNORE_PASSABLE + USE_BOX;  
      
     if(key_w == 1)
     { 
       // perform movement
       c_move (my,vector(speed * time_step,0,0), nullvector, move_mode);
     }
     
     if(key_s == 1)
     {
        c_move (my,vector(-speed * time_step,0,0), nullvector,move_mode);
     }

     // perform rotation
     if(key_a == 1) { my.pan += rotation_speed * time_step; };
     
     if(key_d == 1) { my.pan -= rotation_speed * time_step; };
     
     if(key_q == 1) { my.tilt += 1; }

     if(key_z == 1) { my.tilt -= 1; }
    
     wait(1);
  }
}
[code]


Re: Have trouble learning to make player entity move [Re: Kevinper] #237766
11/22/08 05:15
11/22/08 05:15
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
Originally Posted By: Kevinper
That's what I'm looking for is the basics. But how do I assign my entity to use the script? And do I put in in the Lite-c script or the wdl file?


As has been mentioned, a tutorial would do you good, but for my little example there, there are two ways:

1. Place the entity in WED, go to the Behavior panel, click on the New button (the open folder icon under the word "action") and if you don't see the action on the list, write the action down (it IS case sensitive)

2. Create the entity via script with ent_create("yourmodel.mdl",vector,moveMe);


Also, my example is Lite-C, so you'd save it in a .c file, but if you wanted C-Script, just remove the parenthesis at the end of the aciton name.


Last edited by heinekenbottle; 11/22/08 05:17.

I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: Have trouble learning to make player entity move [Re: heinekenbottle] #237826
11/22/08 18:26
11/22/08 18:26
Joined: Nov 2008
Posts: 24
Nevada, USA
Kevinper Offline OP
Newbie
Kevinper  Offline OP
Newbie

Joined: Nov 2008
Posts: 24
Nevada, USA
Now that is making sense. I didn't know you could type in an action. Cool. I think I can make progress today and maybe make some sense of all this stuff that I've read.

Thank you all!


Kevin
Re: Have trouble learning to make player entity move [Re: Kevinper] #237833
11/22/08 19:57
11/22/08 19:57
Joined: Nov 2008
Posts: 24
Nevada, USA
Kevinper Offline OP
Newbie
Kevinper  Offline OP
Newbie

Joined: Nov 2008
Posts: 24
Nevada, USA
Alright. I have made a level in WED. I have a model of a spaceship and some prefabs and a sphere of stars surrounding it.

I made a lite-c file called move.c with the following code:

VECTOR speed;

vec_zero(speed);

action moveMe()
{
while(1)
{
my.pan += 5 * (key_a - key_d) * time_step;
speed.x = 5 * (key_w - key_s) * time_step;
c_move(my,speed,nullvector,IGNORE_PASSABLE | GLIDE);
wait(1);
}
}


I added the moveMe action to my spaceship.

I have included the move.c file to read before the level comes up (with the rest of the includes).

When I run the level, it says that moveMe cannot be found.

I did click the A6 template for the script.


Kevin
Re: Have trouble learning to make player entity move [Re: Kevinper] #237836
11/22/08 20:04
11/22/08 20:04
Joined: Apr 2005
Posts: 69
G
Goodberry Offline
Junior Member
Goodberry  Offline
Junior Member
G

Joined: Apr 2005
Posts: 69
Just a guess... does your include line have brackets <> or quotation marks "" around the file name? I've run into this when I accidentally used brackets.

The line should look like this:

#include "move.c";

not like this:

#include <move.c>

Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1