Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, 7th_zorro), 1,203 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help with coding basic movement controls? I'm stuck. #226406
09/09/08 18:05
09/09/08 18:05
Joined: Sep 2008
Posts: 76
Max_Prower Offline OP
Junior Member
Max_Prower  Offline OP
Junior Member

Joined: Sep 2008
Posts: 76
Hey guys, and AGAIN I'm sorry if there some blatantly obvious thread with the answer already, but I searched for "coding movement" and didn't notice any helpful results after skimming the first ten or so pages.

Okay, I adapted this toy game thingy from Earthball, as otherwise else it would just display a black screen. So I've been trying to turn this Earthball adaption into a third-person RPG, but here are the few problems I've been having. I don't know how to code a third person camera that follows an assigned target, and because of that physics thingy in earthball, if I use a key to nudge it forward it will tip over.

So, in a nutshell... What I need help with is a way to simply be able to 'drag' the ball in different directions by holding the WASD keys, and a way to get the camera to follow that a certain target, like a camera follows your character in games like WoW, Runescape and American Mcgee's Alice.

Here's the code that I adapted from Earthball if it will help. :3

Code:
///////////////////////////////////////////////////////////////
// earthball.c - physics example for lite-C pure mode
///////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////////////////////////////////////
// some global definitions 

PANEL* pSplash = { bmap = "logo_800.jpg"; }

TEXT* tHelp = { 
   pos_x = 10; pos_y = 10;
   font = "Arial#24bi";
   flags = SHADOW;
   string("Press [Space] to jump!"); 
}

ENTITY* eBall;
ENTITY* Pillar;

SOUND* sPong = "tap.wav";

VECTOR vSpeed, vAngularSpeed, vForce, vMove;
		
///////////////////////////////////////////////////////////////
// This is our event function for the ball impact.
function Plop()
{
// Play a ball impact sound.
	ent_playsound(eBall,sPong,150);
}

function Music()
{
// Play a track.
 media_loop("track1(2).mid",NULL,9001);
}

// Function for kicking the ball in camera direction.
function Jump()
{
// Create a local speed vector
   VECTOR vJump;
// Use a horizontal and vertical speed to give the ball an upwards kick.	
   vJump.x = 0; vJump.y = 0; vJump.z = 300;
// Rotate it in camera direction.   
//	vec_rotate(vKick,camera.pan);
// Now apply the speed to the ball, and play a hit sound.
	phent_addvelcentral(eBall,vJump);
	Plop();
}

//Function for moving forwards
function Forwards()
{
	VECTOR vJump;
	vJump.x = 100; vJump.y = 0; vJump.z = 0;
	phent_addvelcentral(eBall,vJump);
	vForce.x = -7*(key_force.x);	// pan angle
vec_accelerate(vMove,vSpeed,vForce,-30.5);
}

function Backwards()
{
	VECTOR vJump;
	vJump.x = -100; vJump.y = 0; vJump.z = 0;
	phent_addvelcentral(eBall,vJump);
	vForce.x = -7*(key_force.x);	// pan angle
vec_accelerate(vMove,vSpeed,vForce,-30.5);
}
///////////////////////////////////////////////////////////////
// If a function is named "main", it's automatically started
function main()
{
// Activate 800x600 screen resolution and stencil shadows,
// and set the sound at full volume.
// Video_mode is a 'redefine' variable that has to be set 
// before initializig the video device during the first wait().
   video_mode = 7;
	shadow_stencil = 1;
	sound_vol = 100;

// Make the splash screen visible.
	set(pSplash,VISIBLE);

// After a panel is set to VISIBLE, we have to wait 3 frames
// until we can really see it on the screen.
// The first frame paints it into the background buffer,
// two more frames are needed until the background buffer
// is flipped to the front in a triple buffer system.
	wait(3);

// Before we can create level entities, a level must be loaded.
// We'll use the small terrain from the techdemo for a level.
// We have to wait one more engine frame to ensure that the level 
// exists and is ready to be filled with level entities.
	level_load("small.hmp");

// create a sky cube on layer 0
	ent_createlayer("trippysky2.tga", SKY | DOME | DOME, 1);
	ent_createlayer("red.tga", SKY | CUBE | VISIBLE, 0);


// Let's now create a ball at position (0,0,100).
// The vector function converts 3 floats to a temporary var vector
// for passing positions to engine functions.
	eBall = ent_create("lamppost.mdl",vector(0,0,0),NULL);
// Set an entity flag to cast a dynamic shadow
	set(eBall,SHADOW);
// Use one of the default materials for giving it a shiny look
	eBall.material = mat_metal;

// Now let's set the ball's physical properties. 
	phent_settype(eBall,PH_RIGID,PH_BOX);
	phent_setmass(eBall,1,PH_BOX);
	phent_setfriction(eBall,100);
	phent_setelasticity(eBall,0,0);
	phent_setdamping(eBall,50,50);

// We add a small speed to give it a little sidewards kick. 
	phent_addvelcentral(eBall,vector(0,0,0));

// A ball game would be no fun without gravity.
	ph_setgravity(vector(0,0,-500));

// Another event: if the ball hits something, a sound shall be played. 
// We set the event function and the enable_friction mask for triggering 
// the event at physics collisions. Note that the minimum speed - 
// the third parameter of phent_setelasticity - determines the
// sensitivity of this event.
	eBall.event = Plop;
//	eBall.emask |= ENABLE_FRICTION;
	
// Remove the splash screen and display the text.
	pan_remove(pSplash);
	set(tHelp,VISIBLE);

// We want to kick the ball by hitting the [Space] key.
// Assign the 'Kick' function to the on_space event.
	on_space = Jump;
	on_w = Forwards;
	on_s = Backwards;

// play the sound as if someone had kicked the ball into play
	Music();

// During the main loop we're just moving the camera
	while (1) 
	{
// For the camera movement we use the 
// vec_accelerate() function. It accelerates a speed and
// is not dependent on the frame rate - so we don't need to
// limit the fps in this example. This code is equivalent
// to the built-in camera movement, but uses different keys.
		vForce.x = -7*(key_force.x + mouse_force.x);	// pan angle
		vForce.y = 7*(key_force.y + mouse_force.y);	// tilt angle
		vForce.z = 0;	// roll angle
		vec_accelerate(vMove,vAngularSpeed,vForce,-0.067);
		vec_accelerate(vMove,vAngularSpeed,vForce,0.567);
		vec_add(camera.pan,vMove);		

		vForce.x = 3 * (key_w - key_s);		// forward
		vForce.y = 3 * (key_q - key_e);		// sideward
		vForce.z = 3 * (key_home - key_end);	// upward
		vec_accelerate(vMove,vSpeed,vForce,-30.5);
				vec_accelerate(vMove,vSpeed,vForce,0.6);
		vec_rotate(vMove,camera.pan);
		vec_add(camera.x,vMove);
		wait(1);
	}
	

// We don't need to free our created entities, bitmaps and sounds. 
// The engine does this automatically when closing.
}


Re: Help with coding basic movement controls? I'm stuck. [Re: Max_Prower] #226459
09/09/08 21:08
09/09/08 21:08
Joined: May 2006
Posts: 398
Bot190 Offline
Senior Member
Bot190  Offline
Senior Member

Joined: May 2006
Posts: 398
if your doing an rpg like World of Warcraft or Runescape then that code probably isn't a good base to be working from. The first, or one of the first places to look is the AUM. The manual is also your friend.


Wait, there isn't a "Make My Game Now" button?
Re: Help with coding basic movement controls? I'm stuck. [Re: Bot190] #226482
09/10/08 00:19
09/10/08 00:19
Joined: Aug 2008
Posts: 61
Neurosys Offline
Junior Member
Neurosys  Offline
Junior Member

Joined: Aug 2008
Posts: 61


See more code and crap @ www.neuroticnetworks.com
Re: Help with coding basic movement controls? I'm stuck. [Re: Neurosys] #226706
09/10/08 20:20
09/10/08 20: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

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