Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,618 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Rotate while Moving #180039
01/26/08 17:16
01/26/08 17:16
Joined: Jan 2008
Posts: 13
Everywhere
ajsquared Offline OP
Newbie
ajsquared  Offline OP
Newbie

Joined: Jan 2008
Posts: 13
Everywhere
I am working on a game that involves the player moving a ball through a maze, and I would like to make the ball roll while it moves. How would I do this?

I've tried using using c_rotate and ang_add, but these just seem to change the direction the ball is facing.

Last edited by ajsquared; 01/27/08 16:02.
Re: Rotate while Moving [Re: ajsquared] #180040
01/27/08 21:46
01/27/08 21:46
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline
User
MrCode  Offline
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
You need to use the physics engine to do this:

Code:

float thrustX,thrustY;

...

void phys_ent()
{
ENTITY* pent= me;
phent_settype(me,PH_RIGID,PH_SPHERE);
phent_setmass(me,2,PH_SPHERE);
phent_setfriction(me,60);
phent_setelasticity(me,30,20);
phent_setdamping(me,40,30);
while(pent)
{
phent_addcentralforce(me,vector((thrustY * 1000) * (key_cur - key_cul),(-thrustX * 1000) * (key_cur - key_cul),0));
phent_addcentralforce(me,vector((thrustX * 1000) * (key_cuu - key_cud),(thrustY * 1000) * (key_cuu - key_cud),0));
thrustX= cos(-camera.pan);
thrustY= sin(camera.pan);
vec_set(temp,pent.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);
wait(1);
}
}



This should allow you to control a ball physics entity with the arrow keys. The direction is always relative to the view (meaning forward is always away from the camera, backward is always towards the camera, etc.).

You may need to change a few things, like changing the "void" to "action" (if you want to attach it o an entity in WED), and changing the variable declaration if you're using C-Script (from "float thrustX,thrustY;" to "var thrustX; var thrustY;").


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Rotate while Moving [Re: MrCode] #180041
01/27/08 23:37
01/27/08 23:37
Joined: Jan 2008
Posts: 13
Everywhere
ajsquared Offline OP
Newbie
ajsquared  Offline OP
Newbie

Joined: Jan 2008
Posts: 13
Everywhere
Thanks! This is exactly what I'm looking for.


If the facts don't fit the theory, change the facts.

Moderated by  HeelX, Spirit 

Gamestudio download | 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