Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AbrahamR), 717 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How do I make a camera rotate with an entity as it's center? :) #256457
03/16/09 21:42
03/16/09 21:42
Joined: Sep 2008
Posts: 76
Max_Prower Offline OP
Junior Member
Max_Prower  Offline OP
Junior Member

Joined: Sep 2008
Posts: 76
What I mean is. I've got my basic movement, gravity and everything sorted out. Now, what I would like to create is a camera.

The camera that I am trying to create is basically a basic third-person shooter camera. One that keeps the player entity as it's center and turns with it when I move the mouse. (I made it so that the character's pan changes with mouse_force.x)

So basically, how can I make my camera center around a model?

Also, how can I make it so that the camera doesn't go through walls? Say, if I went around a corner by moving sideways, that when the camera lost sight of the player; it would zoom to the player's view again?

I apologise if there is a blatantly obvious solution; but I did a brief bit of searching, and I couldn't find anything.

Re: How do I make a camera rotate with an entity as it's center? :) [Re: Max_Prower] #256589
03/17/09 17:27
03/17/09 17:27
Joined: May 2008
Posts: 331
Lithuania, Vilnius
Jaxas Offline
Senior Member
Jaxas  Offline
Senior Member

Joined: May 2008
Posts: 331
Lithuania, Vilnius
You can find code in forum, but what the heck, here's the basic that you'll need:

camera.x = player.x-distance* cos(camera.pan);
camera.y = player.y-distance* sin(camera.pan);

Experiment with other camera values your self wink


The smaller the bug, the harder it is to kill.
_________________________________________
Forklift DEMO (3dgs)
Re: How do I make a camera rotate with an entity as it's center? :) [Re: Max_Prower] #256592
03/17/09 17:43
03/17/09 17:43
Joined: Mar 2009
Posts: 8
S
Sonne Offline
Newbie
Sonne  Offline
Newbie
S

Joined: Mar 2009
Posts: 8
camera.x = me.x + fcos(my.pan,-1 * distance);
camera.y = me.y + fsin(my.pan,-1 * distance);
vec_diff(temp.x,me.x,camera.x);
vec_to_angle(camera.pan,temp.x);

I found that in one of the tutorials on the wiki. Works for me. I too have to resolve the camera going into walls which I believe was also addressed in those tutorials but I haven't looked into that portion yet.
Wiki Tutorials

Re: How do I make a camera rotate with an entity as it's center? :) [Re: Sonne] #256695
03/18/09 12:46
03/18/09 12:46
Joined: Sep 2008
Posts: 76
Max_Prower Offline OP
Junior Member
Max_Prower  Offline OP
Junior Member

Joined: Sep 2008
Posts: 76
Trig... My mortal enemy. Thanks for the help, you guys! ^^

One thing though, I'm curious. Where (school here doesn't teach it for some reason) can I learn trigonometry? And how does Trigonometry apply in Gamestudio?

Re: How do I make a camera rotate with an entity as it's center? :) [Re: Max_Prower] #256698
03/18/09 13:23
03/18/09 13:23
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Trigonometry and vector/matrix algebra are the principles that 3D graphics are built up off. Without an understanding of them its pretty hard to fully appreciate what is going on. If you're not that comfortable with maths or just have gaps in your knowledge then i recommend a maths book.

I have used this book and it helps alot...

3D maths primer for 3D Graphics/Games.

http://www.amazon.com/Primer-Graphics-Development-Wordware-Library/dp/1556229119

Re: How do I make a camera rotate with an entity as it's center? :) [Re: DJBMASTER] #256762
03/18/09 21:34
03/18/09 21:34
Joined: Sep 2008
Posts: 76
Max_Prower Offline OP
Junior Member
Max_Prower  Offline OP
Junior Member

Joined: Sep 2008
Posts: 76
I'm not an adult and don't have my own money to be able to spend on the net. Are there any free resources? smile

And I manged to find a solution. I used the camera script from David Lancaster's Kindom Hearts tutorial. Here is what I used (I tinkered with the values a little).

Code:
vec_set(camera.x,vector(my.x + fcos(my.pan,-466),my.y + fsin(my.pan,-466),my.z +
160)); 
vec_diff(temp.x,my.x,camera.x); //make the camera look towards the player
vec_to_angle(camera.pan,temp.x);//place the camera behind the player
}


Last edited by Max_Prower; 03/22/09 13:14.

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