So I am working on something and in my project square is my player and circle and triangle are enemies So How can I move my enemy towards the my player I tried lot of things but I failed… Please help me🙂
https://i.stack.imgur.com/UbZJd.jpg
Give simple BP Solution
I'm trying to replicate the NPC movement in Endless Sky. Checkout Endless Sky Github's Repository using Phaser 3.
The characteristic of the NPC is that they have drag and rotate to face the direction they intend to travel. I can do this with the player character using
player.body.setAngularVelocity(0);
player.body.setAcceleration(0)
scene.physics.velocityFromAngle(player.angle - 90, 400, player.body.acceleration)
But I can't seem to get it right with an npc - and by "get it right" I mean a smooth movement of the sprite turning/tweening to face the new coordinates and then moving towards it.
The closest I had was the sprite seemed to be moving correctly but the image/texture of the sprite was frantically changing angle, sometimes doing a 360 rotation. Perhaps I have a fundamental misunderstanding of the body.angle / body.rotation as well as the math involved?
At the moment, I am passing the npc a random vector to travel to:
enemy.stateMachine.transition('patrolling', [Phaser.Math.Between(-3500, 3500), Phaser.Math.Between(-3500, 3000)])
-3500 and 3000 being the bounds of my game world.
Any help appreciated.
Im making a simple 3d game where Ive got some boats colliding and changing directions to avoid eachother.
Part of the collision handling is built around bouncing and then diverting the heading direction slightly (boat A hit boat B, A bounces back then rotates say 10 degrees to the left and resumes movement)
So far, Ive just updated the heading direction, which looks a bit abrupt. I intend to interpolate from the old heading to the new one. It is very simple, the heading is always just an angle around one axis. So basically its going from say 90 degs to 110 degs.
Im aware of quaternions and slerp, which would give me a constant velocity (my rotation should be silky smooth). But I just end up feeling like its using a sledge hammer to kill a fly. What is really the consequence of just doing a regular vanilla linear interpolation from 90 to 110 for the rotation angle? Will it even be visually noticeable that I have used quaternions instead of the much simpler and much cheaper linear interpolation of angle values? I have no special important "key frames" that need to be hit - there is no "animational data" at all, the 3d models are static.
So if someone could shed some light of what potential problems I could run into if I just interpolate the rotation degrees instead of using slerp, it would be much appreciated.
Thanks
/Jim
How can I make a camera that I can move around and rotate around its own axis in processing 2+?
I have a camera that I can move around in the world space and have some kind of rotation:
frustum(-10,10,-10,10,10,2000);
translate(camX,camY,camZ);//I move around by adding to these values when a button is pressed
rotate(angleX,1,0,0);//same here...
rotate(angleY,0,1,0);
rotate(angleZ,0,0,1);
Bu the problem with this is that the rotation is centered in the scene, meaning that I get very strange rotations when moving further away from the scene's center coordinates. Why does that happen when I have translated before rotating?
Thanks to Nicolás Carlo and his suggestion to watch This Youtube playlist made by Jorge Rodriguez I was able to fix what I almost made right the first time.
All I had to do was really just to do some simple trigonometric calculations to get the forward-vector from the angles I got, and then just add the camera position to that for the centerX,centerY,centerZ values in camera();
Ex. where camPos is the current position 3D-Vector and vecForward is the calculated 3D-forward vector that I needed.
vecForward.x = cos(yaw)*cos(pitch);
vecForward.y = sin(pitch);
vecForward.z = sin(yaw)*cos(pitch);
camera(camPos.x,camPos.y,camPos.z, camPos.x+vecForward.x,camPos.y+vecForward.y,camPos.z+vecForward.z, 0,1,0);
If some of you do not know, Pitch is the up-down angle and Yaw is left-right angle of the camera.
And as a last note here,I highly suggest watching Rodriguez "Math for game developers" that Carlo suggested since every video explains at least one of the most important/oftenly used mathematical solutions at a time to different problems and then giving an example in the end.
How should I go about adding camera collision to a terrain in three.js.
The terrain is from 'mrdoob's three.js' examples and is randomly generated and I am currently converting it to height map.
I am thinking of implementing the collision as follows:
Create a 'box' object around the camera
If the box object is not touching the terrain, move the camera down.
If the box object IS touching the terrain, keep the Y axis of the camera.
How should I go about doing this?
The theory is that you send a ray from the location you are (camera position) straight down. You find the intersection point and based on the distance you decide what to do. Implementation wise I cannot help you but THREE.Ray should help you.