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 Discussion / Moving two objects together?!

Author
Message
DARKHALO2K
21
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 27th Apr 2006 16:29
Hi there. I was wondering if anybody could supply me with a small example piece of code that allows for an object to be placed at a set distance and position from a player (e.g. fifty pixels to the right of a player) and have it stay at that position with regards to the player model, even whilst moving and rotating.
Sort of like the solar system examples you see, but this would only have the planet rotate around the sun if the sun moves or rotates.
If you've played Phantasy Star Online, then picture the movement of the "Mag's" in accordance with the player.
I would massively appreciate any help here, as my 3D maths is a bit useless and my mind is all other the place lately! I would of course give you credit somehow if I can use the code as I wish, and would aim to show off the fruits of it's use real soon!
Thanks in advance for any genuine help.
General Sephiro
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location:
Posted: 27th Apr 2006 17:57
One simple way of doing it.

You have point or origin, the character position

If you want it always to stay in the same place, for example always to the east of the character, no matter what way he is facing it is simple:

Position the object at characters position, keep the object rotated to the east, and move it forward by per say 50 pixels

If u want it to rotate with the character do the same:
Position object @ character position
Rotate object same rotation as character
and move it forward 50 pixels...

Hope that helps

DARKHALO2K
21
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 27th Apr 2006 18:41
That's the sort of theory I was toying with, thank you for explaining it, though if anybody could turn this into a small code snippet, that'd be awesome.
Also, sorry about accidently posting the topic twice.
General Sephiro
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location:
Posted: 28th Apr 2006 02:25 Edited at: 28th Apr 2006 02:26
I'm confident that you can work it out for yourself. This will be the only way you will learn and become a great programmer .

You can get ANY of the commands you require in help.

You can ask for the theory here..., but now I'm stopping giving out code snippets, it spoils the learning curve.

I could although go as far as helping you lay out your code:


Load in objects
Position objects

Start Loop---------------------

Player Controls - Upkey downkey leftkey rightkey...

Update character Position

Position Object @ char position

Rotate it to same as Character

Move object forward

refresh

Loop ---------------------

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 28th Apr 2006 02:58
Programming is about solving problems, and asking for help sometimes. Asking for code is the last step, when it is more complicated than this.

bibz1st
22
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 28th Apr 2006 18:50
look in the manual or help files for the commands NEWXVALUE(), NEWYVALUE(), NEWZVALUE()
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
DARKHALO2K
21
Years of Service
User Offline
Joined: 4th Sep 2003
Location: UK
Posted: 1st May 2006 01:34
WOW! I'd almost forgotten about this and continued with one of my other projects before I was attempt coding it again, but checked this and found that your code practically plugged right in to mine!
I'm really very greatful TDK. Could I possibly take your name, as to give you proper credit as due?!
Again, many, many thanks. Reading through your code has been a fantastic tutorial aid and I really appreciate the help. Cheers.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st May 2006 06:20
No problem.

Actually, I just discovered that the snippet I posted didn't paste in correctly and had a few lines missing from the start and didn't run.

So, I just added the missing lines and it's OK now...

TDK_Man

Login to post a reply

Server time is: 2025-05-23 17:00:21
Your offset time is: 2025-05-23 17:00:21