Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (EternallyCurious, AndrewAMD, TipmyPip, Quad), 889 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Almost finished!!! Spherical Planet Gravity Test #265913
05/15/09 03:30
05/15/09 03:30
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Code for a person walking around a sphere, always standing with his feet towards the planet and his head away from the planet, and gravity pulls him toward the center of the planet.

I have been working on this very short code. And it is almost finished, mostly it works like it is supposed to but with some small problems.

Even though the code is short, I added lots of comments so it would be easyer to understand. (and hopefully easier to help me)

Code:
#include <acknex.h>
#include <default.c>
#include <windows.h>

VECTOR WorldCenter;
ENTITY* Person;

action Person_Action()
{
	c_setminmax(me);
	Person=me;
	
	while(1)
	{
		//***************PLAYER MOVEMENT*************
		//forward-back
		c_move(Person,vector((5*(key_w-key_s)*time_step),0,0),nullvector,IGNORE_PASSABLE);
		//strafe left-right
		c_move(Person,vector(0,(5*(key_a-key_d)*time_step),0),nullvector,IGNORE_PASSABLE);
		//rotate left-right
		c_rotate(Person,vector((10*(key_q-key_e)*time_step),0,0),USE_AXIS);
		
		//*******ROTATION RELATIVE TO PLANET CORE ***********
		//Rotate Person on WORLD
		VECTOR TempVec;
		vec_set(TempVec,WorldCenter); //temp vector pointing to center of the planet
		vec_sub(TempVec,Person.x); //subtract vectors for planet core (gravity center) and player position to get a direction vetor towards the center
		vec_to_angle(Person.pan,TempVec); //change direction vector to an angle to rotate the model towards the center, almost ok... but my player is looking towards the planet face down, not standing on it!
		Person.tilt += 90; //I did this to fix the person laying face down toward the planet (now it is standing on it correctly)

		//********************GRAVITY*************************
		//check distance to planet surface
		float FloorDist;
		FloorDist=c_trace(Person.x,WorldCenter,IGNORE_ME | IGNORE_PASSABLE);
		if(FloorDist>68)
		{
			c_move(Person,vector(0,0,-5*time_step),nullvector,IGNORE_PASSABLE);//Apply ORIENTED Gravity (relative to player's z axis)
		}
		else if(FloorDist<67)//I had to add this because my test planet is not completely round and has pointy edges where he got stuck
		{
			c_move(Person,vector(0,0,5*time_step),nullvector,IGNORE_PASSABLE);//Push away from planet's pointy edges
		}
		
		wait(1);
	}
}

void main ()
{
	level_load("Luna.wmb");
	vec_set(WorldCenter,vector(0,0,0));

	camera.x=-2000;
	camera.y=0;
	camera.z=100;

	ent_createlocal("Character_M.mdl",vector(0,0,500),Person_Action);
}


What Does Work:
-The level loads (it is a sphere)
-It loads a Model on top of the sphere that is attracted towards it by gravity
-Gravity always pulls the model towards the center of the sphere even if it is on a side or under it.
-The model's pan/tilt/roll angles are modified so the feet are towards the sphere and the head is away from the sphere.
-"w" and "s" keys make him move forward and back
-"a" and "d" keys make him strafe

What Does NOT Work:
-for some reason the model is standing correclty on the planet, but I cannot get him to face where I want (turn left and right with the "q" and "e" keys sometimes dosent work and other times causes random fliping rotations).
-if directly on the north pole he can only move backwards but not forwards (he sometimes spins if i try to move forward)
-if he is standing directly on the south pole he does not move backwards, only forward (he sometimes spins if i try to move back)

I can post the model and level I am using if needed. This is just a little test code and the model/level are very simple.

Any help to get this working would be greatly apreciated
DOWNLOAD:
http://www.megaupload.com/?d=R5U67BBL
Keys: (wasd qe)
w =forward
s =back
a =strafe left
d =strafe right
q =turn left (not working properly)
e =turn right (not working properly)

Last edited by Carlos3DGS; 05/15/09 14:10. Reason: added download and tweaked code

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Almost finished!!! Spherical Planet Gravity Test [Re: Carlos3DGS] #265916
05/15/09 04:35
05/15/09 04:35
Joined: May 2003
Posts: 567
Spain, Canary Islands
Felixsg Offline
User
Felixsg  Offline
User

Joined: May 2003
Posts: 567
Spain, Canary Islands
probably but I can be wrong
the solution not are to move the player (person)
is move the world

with the cam fixed

Re: Almost finished!!! Spherical Planet Gravity Test [Re: Felixsg] #265917
05/15/09 04:45
05/15/09 04:45
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
this can work for Atomic level molecules simulation? at least the atraction?

Re: Almost finished!!! Spherical Planet Gravity Test [Re: MMike] #265920
05/15/09 05:36
05/15/09 05:36
Joined: Apr 2009
Posts: 298
Southern Oceans
KiwiBoy Offline
Member
KiwiBoy  Offline
Member

Joined: Apr 2009
Posts: 298
Southern Oceans
Simply place a model in centre then vec_dist it and let .z do all the work.
You will always be attracted to where ever the model is smile

I think the tilt thing is due to flipping the model upside down where you then encounter gimbol lock probs.


Use the 'manual' Luke, the manual is your friend. 'Self reminder' smile

My WebPage
Re: Almost finished!!! Spherical Planet Gravity Test [Re: KiwiBoy] #265972
05/15/09 11:38
05/15/09 11:38
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
@ Felixsg: That is what I was doing at first, but then I realized that would only work if I was planning to not have anything more than just the ball (an empty planet) in my game forever.
When I start placing people, vegetation, animals, etc... well then each time I take one one step in any direction I would have to start rotating tons of stuff, that would be crazy for the processor, it really is better to just calculate one model's rotation than hundreds of modle's rotations. Besides, if I were to find a way to correclty rotate hundreds of them then i would be able to do just one correctly also (and easier) smile
Nice idea though! I started with that idea also!

@ MMike: If I get it to work correctly... Yes, it will work perfectly for your work. Feel free to copy the code and play around with it. But i'm kind of stuck now, hope I get some help to finish those problems im having.

@ KiwiBoy: If you use the world coordinates its much more complicated than just modifying z. If you are thinking of z relative to the player model (model's axis) then that is exactly what im doing. But for that to work the player's rotation must be calculated correctly so his z axis is always pointing to the center of the planet (actualy i rotate him so his z axis is towards the center, then I trace towards the core to get the distance to the surface of the planet so he can actually even cimb mountains ans stuff). Currently it is working perfectly for walking forwards/back and strafing side to side, the problem is when I want the player to turn to his left/right (for some reason he likes to face the north pole, and if I try to make him turn away from that either nothing happens, or strange crazy rotations occur).

Please someone help me cry


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Almost finished!!! Spherical Planet Gravity Test [Re: Carlos3DGS] #265975
05/15/09 11:45
05/15/09 11:45
Joined: Apr 2009
Posts: 274
atari98 Offline
Member
atari98  Offline
Member

Joined: Apr 2009
Posts: 274
PLease write in German!!
I hate English!!


Meine Fun Websiten
www.free4-fun.de.tl

www.gamer-liga-live.de.tl

Meine Game-Projekt Websiten
www.gamer-projects.de.tl
Re: Almost finished!!! Spherical Planet Gravity Test [Re: atari98] #265977
05/15/09 11:47
05/15/09 11:47
Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Cowabanga Offline
Expert
Cowabanga  Offline
Expert

Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Originally Posted By: atari98
PLease write in German!!
I hate English!!

Can't you understand something simple like this?

Re: Almost finished!!! Spherical Planet Gravity Test [Re: Cowabanga] #265984
05/15/09 12:23
05/15/09 12:23
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
I am not german, and I do not know german, sorry.

It wouldnt hurt to work on your manners, I have never barged in any german conversation to shout "I hate German!!!", LoL...


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Almost finished!!! Spherical Planet Gravity Test [Re: Carlos3DGS] #266000
05/15/09 13:42
05/15/09 13:42
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
WTF.. english is internacional, learn it , or you left behind.. its your choice. Sorry to disapoint you but german is not necessary like english...

Re: Almost finished!!! Spherical Planet Gravity Test [Re: MMike] #266005
05/15/09 14:04
05/15/09 14:04
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Added the download to my main post.
It contains my project files and also a compiled version.

Tweaked code a little but still dosent work (also changed this in main post)


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Page 1 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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