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 / Carbonade, Dark basic pro

Author
Message
LucasH42
12
Years of Service
User Offline
Joined: 7th Nov 2013
Location:
Posted: 7th Nov 2013 19:06
hello guys..
im here in a programming class in which we need to create a game, Carbonade. it is about a can running around collecting fruits. But, i am here wondering how you would make an object you create follow you, like all the code needed. i have created a cone, but i would love it if I could make it follow me to spice up my game. thanks!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 8th Nov 2013 05:25
Search feature at the bottom of the site is your friend

Out of interest, if your using DBP in a programming class, is there someone teaching it or can you choose whatever language you like?

"Get in the Van!" - Van B
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Nov 2013 09:52
One easy way, assuming that both objects are on the same Y height, is to just point the cone at the object you want it to follow, move it forward slightly, then rotate it back to 0,0,0...

Point object obj,camera position x(),camera position y(),camera position z()
Move object obj,0.1
Rotate object obj,0,0,0

It's kinda cheating, but it works

One thing you could do is have the cone act eerily intelligent, just by having it move out of your way...

Work out the distance between the camera and cone

dx#=object position x(obj)-camera position x()
dz#=object position z(obj)-camera position z()
d#=sqrt((dx#*dx#)+(dz#*dz#))

Now say your ideal distance, or safe radius around the cone is 50 units...

md#=d#-50.0
if md#<-0.1 then md#=-0.1
if md#>0.1 then md#=0.1

Then use md# as the cones movement amount:

Point object obj,camera position x(),camera position y(),camera position z()
Move object obj,md#
Rotate object obj,0,0,0

So if the player is less than 50 units away, the cone will move back, if the player is more than 50 units away, it'll move forward. So, if you run into the cone it'll just keep moving away from you - I wish all NPC's in games did the same thing

I am the one who knocks...
TeknoCyber
12
Years of Service
User Offline
Joined: 8th Nov 2013
Location:
Posted: 8th Nov 2013 17:38
Quick Question, would you like a health bar too, or just have a cone touch yu and die? maybe it knocks you back and you loose health, and if he touches you 4 times you die. Just a thought.

"It's not death I fear, I fear not being ready for it." -Tristan Green
LucasH42
12
Years of Service
User Offline
Joined: 7th Nov 2013
Location:
Posted: 8th Nov 2013 19:19
ok thanks for the coding but i was wondering also where to put it too. do you know where i would put it in my coding?
SamKM
17
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 9th Nov 2013 00:15
You'd need to show us your code before we could help you with that
LucasH42
12
Years of Service
User Offline
Joined: 7th Nov 2013
Location:
Posted: 9th Nov 2013 02:27
yea i want the character to "die" when it gets hit by it..
LucasH42
12
Years of Service
User Offline
Joined: 7th Nov 2013
Location:
Posted: 9th Nov 2013 02:28
yes. i want to know how to make the object follow you then when it gets the character, you lose
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 9th Nov 2013 06:15 Edited at: 9th Nov 2013 06:26
Quote: "all the code needed"
If this is a class, wouldn't something like this be cheating? If it isn't then why wouldn't the teacher just help you with the code?

Anyway, here's a basic example of what you'd want. It's commented, so try to make sense of the commands so you can modify it as needed.



http://www.indiedb.com/games/max-vs-mars

Login to post a reply

Server time is: 2026-07-07 00:08:01
Your offset time is: 2026-07-07 00:08:01