Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Object movement based on camera angle

Author
Message
BlackChaos
16
Years of Service
User Offline
Joined: 2nd May 2010
Location: London
Posted: 25th Sep 2011 04:06
Does anyone know an easy way rotate an object based on the cameras Y angle?

For example, the character object would seemingly always walk away, towards, right or left no matter the angle of the camera.

bchaos101
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 25th Sep 2011 04:44 Edited at: 25th Sep 2011 04:55
What are you trying to accomplish? Do you want the character object to always walk away from the camera? Or do you want the character to rotate around the camera, always facing the direction of the camera (a 3rd person perspective)?
Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 25th Sep 2011 10:43
Assuming that you want 3rd person controls, and you want them to be awesome.

Well you can get the angle of the camera, and the users input, so..






This was a fun programming exercise, and I hope that it helps.

Because some of the variables were so large, I didn't use them in certain areas of the code, so if you change the values of certain variables, there could be some errors.
Such as if you changed the variable YourCharacter to a value of 3.
So you might want to fix some of that stuff.

The controls use the arrow keys, and the mouse, have fun, and put the code to good use.



I like games, and stuff.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 25th Sep 2011 16:19 Edited at: 25th Sep 2011 16:21
Yeah you move the camera not the objects, and lock the camera to the player.

Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 25th Sep 2011 20:36 Edited at: 25th Sep 2011 20:50
I guess locking the camera to the character would be an easy way to do that, but it makes the character kinda stiff, always in the same direction of the camera, so you can only see the characters back. Just fine for a first person game, or if you want a game that is both first person and third person.

I added a couple of lines more, for adjusting the X angle of the camera. I didn't use timers, I thought that it would be easier to just use the frames in the loop.



Again, I hope that this help you out.

And feel free for anybody to simplify the code, fix any glitches, and make it more efficient. Just post it here so we can all see it.

I like games, and stuff.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 25th Sep 2011 20:39
I didn't mean lock it not to move, I meant that the opening post describing moving the objects to match the camera was the wrong way round.

Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 25th Sep 2011 21:21
I thought you meant lock, as in not rotate differently then the camera.

But yeah, always facing the camera, isn't the best for 3rd person games. I guess it just depends on what kinda game your making.

There are a lot of different control setups, and the controls are very important.

I like games, and stuff.
BlackChaos
16
Years of Service
User Offline
Joined: 2nd May 2010
Location: London
Posted: 25th Sep 2011 22:41
Thanks guys, this helped

bchaos101
Sazex
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 14th Dec 2011 03:30 Edited at: 14th Dec 2011 04:01
Sorry to bump this thread up, but I didn't think I should create a new
topic for the same thing...

Anyways, Webber's code works very well, but I'm having one annoying problem,

when I press the "w" key my character turns and starts to walk towards the camera,
and if I press the "s" button, my character still walks towards the camera,
also the wobble glitch is still somewhat there, especially when I press the spacebar to jump

can anyone help me?

heres my entire code:




and heres a picture:
http://i250.photobucket.com/albums/gg258/sazex/cameracontrolprob.png

sazex

Login to post a reply

Server time is: 2026-07-10 10:43:45
Your offset time is: 2026-07-10 10:43:45