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 / ask rotate

Author
Message
lidongheng
13
Years of Service
User Offline
Joined: 10th Jan 2011
Location:
Posted: 11th Jan 2011 04:55
I need ask everybody a questions I\\\'m build a 3d game
but i\\\'m find a problem in it I can\\\'t rotate right
the enemy\\\'s model to follow the player\\\'s model please
help me[email]

lidongheng
BiggAdd
Retired Moderator
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: != null
Posted: 11th Jan 2011 09:12
What Programming Language or Game maker are you using?
Dark Basic? Dark Basic Pro? FPSC? Dark GDK?

This is in the wrong place currently, but if you let me know what you are making your game in, I can move it to a place where you will get more help.

Link102
19
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 11th Jan 2011 16:54 Edited at: 11th Jan 2011 16:54
I'm taking a gues here.

use wrapvalue

like (speudocode)

xrotate(wrapvalue(xangle))

lidongheng
13
Years of Service
User Offline
Joined: 10th Jan 2011
Location:
Posted: 13th Jan 2011 03:17
I use Dark Basic to buid a game the two model fight use his sword
I want to rotate right use enemie's sword to hit the Player my Problem is I need the Enemie move when Player move

lidongheng
lidongheng
13
Years of Service
User Offline
Joined: 10th Jan 2011
Location:
Posted: 13th Jan 2011 14:46
Please answer me everybody

lidongheng
lidongheng
13
Years of Service
User Offline
Joined: 10th Jan 2011
Location:
Posted: 13th Jan 2011 17:18
Please answer me sir

lidongheng
BiggAdd
Retired Moderator
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: != null
Posted: 13th Jan 2011 19:03 Edited at: 13th Jan 2011 19:21
Stop spamming the boards!!!!!!
People will reply in due course, I was waiting to hear what language you are using so I could move it to the correct board.


This is not msn and it will take time for people to respond. Do not double post and create multiple threads about the same subject!


I've moved you to the DarkBasic Discussion forum, this is the place you need to start if you are using DarkBasic.

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 13th Jan 2011 19:30
Alright, lemme see if I got this right.

You have 2 characters, lets call them Bob and Jim. Jim is being controlled by the player. Bob hates Jim because Jim got the last Snickers bar at the supermarket. Now Bob is out for blood....and snickers. So he grabbed a sword and is trying to kill Jim.

Your trouble is you can't figure out how to get Bob from his house to wherever Jim is on his morning jog (a moving target). Once he gets there, you need him to use his sword.

Alright, first, the motion control. I am assuming all motion is on a flat plane and there are no obstructions (if there are things in the way, you need obstacle avoidance AI and I'm not super awesome with that).

Imagine it from a birds-eye perspective such that the positive Z axis goes straight up and the positive X axis goes to the right. The angle from Bob to Jim can be found mathematically using basic trig.

Angle=atan((JimZ-BobZ)/(JimX-BobX))

Don't forget a check to make sure that JimX-BobX doesn't evaluate to 0 (essentially, if they are on the same X coordinate, just set the angle to 90 or 270 depending on if Jim is above or below Bob).

To figure out how far he needs to turn, subtraction works wonders:

AngleToTurn=Angle-OBJECT ANGLE Y(Bob)

So if Bob is looking up (angle=90) and Jim is at an angle of 135 to him, then that means that Bob will need to turn 135-90=45 degrees to point at him.

Now if AngleToTurn is <10 (arbitrarily chosen as the max Bob can turn in an instant) then you can just turn him to face Jim

Point Object Bob,JimX,JimY,JimZ

If AngleToTurn is >10 then we want to turn Bob 10 degrees towards that goal. How do we do that? Magic tricks:

Direction=AngleToTurn/ABS(AngleToTurn)
TurnAngle=10*Direction

Now if AngleToTurn is negative, Direction will be -1 (since ABS is the absolute value). If it is positive, Direction will be 1. Once again, don't forget to check for a 0 denominator).

Then you turn him, use Yrotate and wrapvalue.

Yrotate Bob,Wrapvalue(BobY+TurnAngle)

Then You move him.

Move Object Bob,BobStepSize

NOTE FOR COOL AWESOMENESS: Change BobStepSize depending on how far away he is from Jim. If Jim is far away, Bob is sprinting, if Jim is right around the corner, Bob won't sprint because he'll overshoot Jim.


Attacking is simple, just create the animation in an external 3D modeler and then use PLAY OBJECT Bob.


Hope this helps, I won't be back for 5 hours or so. I'll try to throw some code together then.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose

Login to post a reply

Server time is: 2024-03-29 06:03:44
Your offset time is: 2024-03-29 06:03:44