ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator Make a character look at player (me)
person icon
Dieter
Guest
Quote
2023-09-11 18:00:10

@just_in_case, I absolutely agree. In school they don't tell you that this sinus, cosinus tangents stuff will be vital one day in order to fight the encircling zombie hordes ^^ .

Esp. in 2D games coding, the day one grasps this is like a geometric catharsis.

person icon
Dieter
Guest
Quote
2023-09-12 13:53:21

While we're on the subject, I'd like to give some further advice, that may be useful for others too, in the future.

Pointing the NPC at you immediately may look quite unnatural in a game. Therefor it may be a good idea to use what I call a delayed rubberband relation.

You would not point the NPC directly at the camera, but use an intermediary position, that follows the camera slightly delayed, but follows the faster, the quicker the camera moves.

For the sake of simplicity one may not do this with the angle, because wrapping the 360 degrees may be troublesome, but instead just delay the position in question.

So you check the camera position, as well as this delayed objects position (eg a folder node). You calculate the distances on XYZ, then you add something like 10% of the distance on each axis to the delayed objects position, so it takes a step towards the camera. If the player stands still, that object will catch up smoothly.

Initially the object is positioned at the cameras location.

Then frequently do something like:

xyz1=ccbGetSceneNodeProperty(player,"Position");
xyz2=ccbGetSceneNodeProperty(object,"Position");
x=xyz2.x+(xyz1.x-xyz2.x)/10;
y=xyz2.y+(xyz1.y-xyz2.y)/10;
z=xyz2.z+(xyz1.z-xyz2.z)/10;
ccbSetSceneNodeProperty(object,"Position",x,y,z);


And then you would do the atan2 thing with this object, instead of the camera.


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |